Wordpress-Using wpdb to connect to a separate database

Below is the code to connect to a separate database in wordpress.

$mydb = new wpdb('username','password','database','localhost');
$rows = $mydb->get_results("select Name from my_table");
echo "
    "; foreach ($rows as $obj) : echo "
  • ".$obj->Name."
  • "; endforeach; echo "
";

No comments:

Post a Comment