The wpdb object can be used to access any database and query any table. Absolutely no need to be WordPress related, which is very interesting.
The benefit is the ability to use all the wpdb classes and functions like get_results, etc so that there’s no need to re-invent the wheel.
Here’s how:
1 2 3 4 5 6 7 |
$mydb = new wpdb('username','password','database','localhost'); $rows = $mydb->get_results("select Name from my_table"); echo "<ul>"; foreach ($rows as $obj) : echo "<li>".$obj->Name."</li>"; endforeach; echo "</ul>"; |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.