• bmeisler

    (@bmeisler)


    I’ve found older threads about this, but I can’t seem to get the following code to work at all:

    $mydb = new wpdb(‘username’,’password’,’database’,’localhost’);
    $querystr =”
    SELECT $mydb->posts.* FROM $mydb->posts
    WHERE $mydb->posts.post_type = ‘post’
    ORDER BY $mydb->posts.post_date DESC
    LIMIT 5″;
    $pageposts = $mydb->get_results($querystr, OBJECT);

    When I parse $pageposts, I get nuthin’.

    The same code works fine with the default $mydb:

    global $wpdb;
    $querystr =”
    SELECT $wpdb->posts.* FROM $wpdb->posts
    WHERE $wpdb->posts.post_type = ‘post’
    ORDER BY $wpdb->posts.post_date DESC
    LIMIT 5″;

    $pageposts = $wpdb->get_results($querystr, OBJECT);

    The above, with the default $wpdb, works fine. Can anybody help with this?

The topic ‘Unable to access external DB with $wpdb’ is closed to new replies.