Using PEAR with multiple databases
| From: | Sims, Benjamin | Date: | Wed, 04 Jun 2003 12:15:01 +0000 |
| Subject: | Using PEAR with multiple databases | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-5782@lists.php.net to get a copy of this message | ||
I would appreciate advice on how to this. I am trying to write a script
which uses PEAR DB to query several different databases. The idea is to be
able to return an array of PEAR DB results, which can then be dealt with in
order to get an array containing results from several different DBs. I have
done this successfully before using the mysql_use_db() for each database in
turn. However, with PEAR DB it seems that I only get results from one of the
databases several times over.
Does anyone know how to successfully handle something like this?
At the moment I have something along the lines of:
<pseudocode>
//The following code is contained in the constructor of the object:
foreach($dataBaseConnectionDetailsArray as $key => $value){
$dbType = $value['dbType'];
$hoste = $value['host'];
$pass = $value['pass'];
$user = $value['user'];
$db_name = $value['db_name'];
$dsn = "$dbType://$user:$pass@$host/$db_name";
$currentConnection = DB::connect($dsn);
//Add the database connection object to an array for later
use
$this->connectionArray[] = $currentConnection;
}
//Later the execute function tries to use each of the connections in turn
and get a result from each for one query
function execute(){
foreach($this->connectionArray as $key => $value){
unset($result);
//reset result each time
$result = $value->query($this->sql);
$this->resultArray[$i] = $result[$i];
$i++;
$value->disconnect();
}//end while
}//end else
}//end foreach
return $this->resultArray;
}// end function
</pseudocode>
Benjamin