Connecting to an external database from within WordPress

I’m trying to connect to and import data into a WordPress 3.5.1 page template from an external database which is hosted on the same localhost server.

I’ve Googled this extensively and have come up with the most preferred solution for this:

Read More
<?php
/*
Template Name: Import Sign data
*/
?>

<?php echo "Import Sign Data Page<br>"; ?>

<?php
$mydb = new wpdb('myname', 'mypassword', 'mydb', 'localhost');
$mydb->show_errors();

$signs = $mydb->get_results("SELECT * FROM signs");
print_r($signs);
foreach ($signs as $sign) {
    echo $sign->title . '<br />';
}

?>

The code above only gives me the first echo, ‘Import Sign Data Page’ and nothing else. No errors, nothing. I’ve checked all my syntax many times now. Can any see where I might have gone wrong here or perhaps suggest some debugging tips?

TIA

Related posts

Leave a Reply

1 comment