[wp-hackers] What is the correct way to open and close another database from a plugin?

Ian Barton lists at manor-farm.org
Mon Jul 12 08:58:52 UTC 2004


I want to be able to open and close another database from within my 
plugin. If I use my standard boiler plate code:

// Connecting the DB
     $Connection = mysql_connect(localhost, my_username, my_password) OR 
die("Cannot Connect: mysql_error()");
     mysql_select_db($DB_name, $Connection) OR die("DB SELECTION FAILED: 
mysql_error()");

     // Select the data
     $Query = "SELECT * FROM Quotes ORDER BY rand() LIMIT 1";
	$Result = mysql_query($Query);
	$Row = mysql_fetch_row($Result);

     // Close DB connection
     mysql_close($Connection) OR die("CLOSE FAILED: mysql_error()");

I seem to end up closing the WordPress database, rather than the 
connection I have created.

wp-db.php has a class to open and close a database, but this seems to be 
hard wired to the WordPress db.

Ian.



More information about the hackers mailing list