Re: equivalent of mysql_select_db in PEAR::DB

From: Date: Thu, 19 Jan 2006 13:06:32 +0000
Subject: Re: equivalent of mysql_select_db in PEAR::DB
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22603@lists.php.net to get a copy of this message
On 19 Jan 2006, at 12:51, hugo wrote:
I would like to know how to use PEAR::DB to select multiple DB on the same server. example (simplified) in mysql : mysql_connect (host, login, pass); mysql_select_db (db1); mysql_query (query); // a query on db1 .. mysql_select_db (db2); mysql_query (query); // a query on db2 I don't see how to change database with PEAR::DB.
The database is typically set-up in the DSN, which I like to define as a constant: define('DSN', 'mysql://user:psw@server/db_name'); And then pass to the Pear:DB connect: $db =& DB::connect(DSN, array('debug' => 2)); To to have 2 connections to two different databases (independant of each other) define('DSN1', 'mysql://user:psw@server/db_name'); define('DSN2', 'mysql://user:psw@server/another_db'); $db1 =& DB::connect(DSN1, array('debug' => 2)); $db2 =& DB::connect(DSN2, array('debug' => 2)); You get the idea. Cheers, Rich -- http://www.corephp.co.uk Zend Certified Engineer PHP Development Services

« previous php.pear.general (#22603) next »