Thread Starter
4mica
(@4mica)
Thanks for getting back to me. What I ended up doing was just reestablishing the connection to the wordpress database on pages that had multiple databases, just by using:
mysql_connect($server,$loginsql,$passsql);
@mysql_select_db($base) or die( “Unable to select database”);
I’m using the non WP database on many more pages than the wordpress database and it was less to change.
I found an alternate solution for calling another MySQL database in a WordPress template. You need to use a new link. From Scriptygoddess’s original example:
blockquote
$databaseConnection = mysql_connect($databaseServer, $databseUsername, $databasePassword) or
die (’I can’t connect to the database.’);
mysql_select_db($databaseName,$databaseConnection);
$query = “SELECT * from tablename;”;
$result = mysql_query($query);blockquote
You just need to add the new_link parameter in the mysql_connect call, which should work in 4.2 and above, like so:
blockquote
$databaseConnection = mysql_connect($databaseServer, $databseUsername, $databasePassword,new_link) or
die (’I can’t connect to the database.’);
mysql_select_db($databaseName,$databaseConnection);
$query = “SELECT * from tablename;”;
$result = mysql_query($query);blockquote
It took me hours to find this solution, but it works perfectly for me – WordPress switches back to using its own database after the mysql_close() as it should. Hopefully this helps others in the future who are having the same problem and don’t want to have to define the database for each query.
bluedauber, many many thanks for that very useful tip!
I’ve done this before, for example I was using XMB Forum with an add on that turned the homepage it into a sort of WordPress, this was way before WordPress was around – and I had some clever stuff set up to link to my other database and retrieve information, but the same problem occured then, when I connect to the other database, it doesn’t retain the first database (the XMB one) so the rest of the script after that point are broken!
Exact same thing happened now I’m trying to do something similar in WordPress, but by adding the ‘new_link’ parameter to my second mysql_connect call, everything works as it should!!
Thanks sooooo much 😀
what is the new_link supposed to be, the table name?