Page 1 of 1
problem with php adodb, overwrite connection
Posted: Mon Oct 04, 2010 3:37 pm
by yacahuma
Code: Select all
$host = 'xxx';
$username='xxx';
$password ='xxx';
$database1 = 'db1';
$database2 = 'db2';
$cn1 = NewADOConnection('mysql');
$cn1->SetFetchMode(ADODB_FETCH_ASSOC);
$cn1->Connect($host, $username, $password,$database1);
$cn2 = NewADOConnection('mysql');
$cn2->SetFetchMode(ADODB_FETCH_ASSOC);
$cn2->Connect($host, $username, $password,$database2);
$sql = "UPDATE table1 set msg='XXX', filename='',prtstatus = 'F',dt_finished=NOW() WHERE id_queue='44'";
$cn1->Execute($sql);
The problem is that $cn1 is now $cn2. You will expect $cn1 to be connected to db1 and not db2. How do I know? Table1 does not exist in db2 and when I execute I get the error saying the table does not exist. If I comment $cn2, everything works.
Re: problem with php adodb
Posted: Mon Oct 04, 2010 3:38 pm
by John Cartwright
Do you want me to delete this thread -- or are you actually going to post something?
Re: problem with php adodb, overwrite connection
Posted: Mon Oct 04, 2010 3:43 pm
by yacahuma
sorry, I submitted by mistake, before the message was finished. Now is complete
Re: problem with php adodb, overwrite connection
Posted: Mon Oct 04, 2010 4:15 pm
by yacahuma
found the problem, ooops
Connection Gotcha: If you create two connections, but both use the same userid and password, PHP will share the same connection. This can cause problems if the connections are meant to different databases. The solution is to always use different userid's for different databases, or use NConnect().
Re: problem with php adodb, overwrite connection
Posted: Mon Oct 04, 2010 8:26 pm
by John Cartwright
Interesting. I never knew that.