get_permalink() always returns empty

First off, you should use get_posts instead of a raw SQL query. Or at least use $wpdb.

<?php
$posts = get_posts(
    array(
        'post_status' => 'publish'
        'numberposts' => -1
    )
);

Then, try passing the entire post object to get_permalink, which saves some database queries.

<?php
foreach( $posts as $p )
{
    $link = get_permalink( $p );
    // do stuff here...
}

The only thing I saw in get_permalink that might cause an empty string it it checking for an empty post ID. Try the above, and see if it works for what you need.