accessing external database
-
Oddly, I used the search function and it returned zero results, although I’m sure there are many questions about this.
In any case… I want to be able to call an external database from inside a page and/or post. How do I do that?
I tried the following in a page (using ‘allow php in posts and pages’ plugin), and get errors indicating “no database selected”:
[php] function main_db_login() { $passwrd='secretpw'; $user='mysitemain'; $db='mysite_main'; $dbcnx = mysql_connect('localhost',$user,$passwrd); if (!$dbcnx) { echo '<p>Unable to connect to the WordPress DB at this time.</p>'; exit(); } } function contact_db_login(){ $passwrd='secretpw'; $user='mysitecontact'; $db='mysite_contact'; $dbcnx = mysql_connect('localhost',$user,$passwrd); if (!$dbcnx) { echo '<p>Unable to connect to the contacts DB at this time.</p>'; exit(); } } function users_db_login(){ $passwrd='secretpw'; $user='mysiteusers'; $db='mysite_users'; $dbcnx = mysql_connect('localhost',$user,$passwrd); if (!$dbcnx) { echo '<p>Unable to connect to the users DB at this time.</p>'; exit(); } } [/php] [php] mysql_close(); contact_db_login(); $dabble=mysql_query("select * from messages"); while($row=mysql_fetch_array($dabble)){ print_r($row); } mysql_close(); echo'closed'; users_db_login(); $dibble=mysql_query("select * from basic"); while($row=mysql_fetch_array($dibble)){ print_r($row); } mysql_close(); echo'closed'; main_db_login(); [/php]
Any help is appreciated.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘accessing external database’ is closed to new replies.