Display data from a non wordpress database on a page template

As Ben suggested, you need to pass the connection details when creating the wpdb class:

$newdb = new wpdb( 'user', 'password', 'database', 'hostname' );

You should also test that the query actually returned something before using the result in a foreach loop:

if ($rows) {
    foreach ($rows as $obj) {
        ...
    }
}

Leave a Comment