Connecting to External Database in WordPress

This is possible to use the wpdb object to access any external database and query any table within your WordPress installation. You can even use all the wpdb classes and functions such as get_results.


$my_external_db = new wpdb(‘username’,’password’,’database’,’localhost’);

$rows = $mydb->get_results(“SELECT * from MYTABLE “);

foreach ($rows as $result) :

echo $ result ->Title;