Jump to content

ADODB Multiple Database Connection Problem


rickm

Recommended Posts

Hi,

 

I'm using ADODB for a PHP project and am having problems with multiple (MySQL) databases.

 

I've looked through all the docs and am stumped. I know how to use PHP and MySQL and I still haven't got a clue why this isn't working.

 

I've got my two connections:

 

$MAINDB = NewADOConnection('mysql');
$MAINDB->Connect($server, $user, $pwd, $db);

$SHAREDDB = NewADOConnection('mysql');
$SHAREDDB->Connect($server, $user, $pwd, $db2);

 

The variables are set just above the connection...the databases are using the same username/password/server.

 

Now, I've got a query below this which is getting data from a table in the first database (MAINDB) however its not working. When I turn debugging on I get a message saying "table shared.table1 does not exist"...even though I've got the query set to use the "$MAINDB" connection.

 

Query:

 

$result = $MAINDB->execute("select * from table1 where value = ".$str."");

 

Error Given (with debugging turned on):

 

--------------------------------------------------------------------------

(mysql): select * from table1 where value = VALUE

--------------------------------------------------------------------------

1146: Table 'shareddb.table1' doesn't exist

 

Any ideas whats going wrong here? I've got the variables all defined correctly, I've got the query using the "$MAINDB" connection, but its still giving me errors :(

 

Any helps is greatly appreciated. Heres a copy of the code with the connection:

 

$server = "removed";
$user = "removed";
$pwd = "removed";
$db = "main";
$db2 = "shared";
$MAINDB = NewADOConnection('mysql');
$MAINDB->Connect($server, $user, $pwd, $db);

$SHAREDDB = NewADOConnection('mysql');
$SHAREDDB->Connect($server, $user, $pwd, $db2);

$MAINDB->debug = true;

$result = $MAINDB->execute("select * from table1 where value = ".$str."");

 

Thanks for your time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.