Re: Re: DB and mysql_select_db
| From: | Jan Rosier | Date: | Thu, 22 Jul 2004 16:55:16 +0000 |
| Subject: | Re: Re: DB and mysql_select_db | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32254@lists.php.net to get a copy of this message | ||
> 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');
Greetings,
Jan Rosier