By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,935 Members | 1,641 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,935 IT Pros & Developers. It's quick & easy.

Multiple database access Bug in adoDB and It's Solution

P: n/a
Fixing Multiple Database bug in adoDB

popular data access layer for php, adoDB can support multiple databases
from different provider at time, but not from same provider. what I
mean is if you instantiate two adoDB connection like this

$db1 = &NewAdoConnection ("mysql");
$db1 = &NewAdoConnection ("oracle");

then you can run queries simultaneously from these connections. but if
you want to access two database from same provider like this

$db1 = &NewAdoConnection ("mysql");
$db1 = &NewAdoConnection ("mysql");

then only last action will remain active and if you use
$db1->execute(), it will actually works on second database. if you want
to access any table from first database, it will generate an error. I
think this is an internal bug in adoDB.

How to fix this bug?

if you open and goto function _connect() you will
find this line at the end

1. if ($argDatabasename) return $this->SelectDB($argDatabasename);

now goto SelectDB function and see what it contains actually.

// returns true or false
function SelectDB($dbName)
$this->databaseName = $dbName;
if ($this->_connectionID) {
return @mysql_select_db($dbName,$this->_connectionID);
else return false;

so it basically returns a boolean value, mysql connection link is
stored in $this->_connectionID variable. Now modify this code like this

1. add this line at the declaration section of

var $__db = array();

2. modify the SelectDB function like this

// returns true or false
function SelectDB($dbName)
$this->databaseName = $dbName;
if ($this->_connectionID) {
$this->__db[$this->_connectionID] = $dbName;
return $this->_connectionID;
else return false;

3. Now open the _query function and modify it like this

// returns queryID or false
function _query($sql,$inputarr)
return mysql_query($sql, $this->_connectionID);
//else return @mysql_unbuffered_query($sql,$this->_connectionID);
// requires PHP >= 4.0.6

That's it!!, now your adoDB supports multiple databases from same

Hasin Hayder
http ://

Mar 27 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.