Reply to Multiple database access Bug in adoDB and It's Solution

Your name:

Reply:


Posted by CountDraculla on 11/18/66 11:43

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");
$db1->PConnect(logininfo_for_first_database)
$db2->PConnect(logininfo_for_second_database)

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 adodb-mysql.inc.php 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 adodb-mysql.inc.php

var $__db = array();

2. modify the SelectDB function like this

// returns true or false
function SelectDB($dbName)
{
$this->databaseName = $dbName;
if ($this->_connectionID) {
@mysql_select_db($dbName,$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)
{
//global $ADODB_COUNTRECS;
//if($ADODB_COUNTRECS)
$this->SelectDB($this->__db[$this->_connectionID]);
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
provider.

Thanks
Hasin Hayder
http ://groups.yahoo.com/group.phpexperts

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация