Re: Re: DB and mysql_select_db

From: Date: Thu, 22 Jul 2004 17:20:28 +0000
Subject: Re: Re: DB and mysql_select_db
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-32258@lists.php.net to get a copy of this message
On Thu, 22 Jul 2004 18:55:16 +0200, Jan Rosier <rosier@interstroom.nl> wrote: > > Jan Rosier wrote: > > > Why does DB/mysql.php make a call to mysql_select_db before every query > ( > > > see simpleQuery($query) ) ? Seems unnecessary to me, since the php > manual > > > stats that after calling mysql_select_db once, every subsequent call to > > > mysql_query() will be made on the active database. > > > > > > > Yes ... so imagine if you want to use multiple databases in a script. > > That's why. > > > > Hans > > > > I thougth of that, but as far I can see is DB::connect the only place where > you can specify a database and the connect method already calls > mysql_select_db. Looks to me there is no need to call it again. > > To use multiple databases you can do: > $db1 =& DB::connect('mysql://someuser:apasswd@localhost/db1', true); > $db2 =& DB::connect('mysql://someuser:apasswd@localhost/db2', true); > $result1 = $db1->getAll('SELECT * FROM table'); > $result2 = $db2->getAll('SELECT * FROM table'); > > Or in the query: > $db =& DB::connect('mysql://someuser:apasswd@localhost', true); > $result1 = $db->getAll('SELECT * FROM db1.table'); > $result2 = $db->getAll('SELECT * FROM db2.table'); > First of all, it's quite possible for both of those "connections" to use the same actual connection to the DB. Because of this, the DB has to be selected, otherwise when you select from DB2, then from DB1, it may be on DB1. I say may because this depends on your version of PHP and your connection parameters. This was put in to make sure that DB worked all the time. -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.pear.dev (#32258) next »