Database Handles
| From: | Samantha Savvakis | Date: | Wed, 06 Dec 2000 01:48:50 +0000 |
| Subject: | Database Handles | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-28808@lists.php.net to get a copy of this message | ||
Hi,
I have a situation where I need to connect to two different databases.
I find that if I open the handle to database ABC, then open handle to
database XYZ, when it goes to call FunctionB, it thinks it's using handle 1
for database ABC but I get the error that it can't find the table
XYZ.TABLENAME - it should be looking for ABC.TABLENAME;
Here is the pseudocode:
<?
require("dbfunctions.inc"); // db wrapper functions
// main routine
$db = db_connection("ABC"); // Database ABC
$code = FunctionA();
// Inside function A, it creates a second DB handle to Database XYZ
$price = FunctionB($code, $db);
// Inside function B, it uses the first DB handle for database ABC
// I do more with $db to database ABC, hence I leave it open
FunctionA()
{
$db2 = db_connection("XYZ"); // Database XYZ
....
do some querying
...
db_close($db2); // Close handle to the second database
}
FunctionB($code, $db)
{
....
do some querying
....
}
?>
Theoretically this should work.
I find that if I go into FunctionA first, without creating the first handle
to database ABC, and then after FunctionA create the first handle to ABC, it
works.
I am using persistant connections mysql_pconnect(); - maybe that's got
something to do with it.
I'm using version 4.0.2 of PHP
Sam