PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB2 » Bug #9449

When interleave queries to two separate databases gives unexpected results

Details

Submitted2006-11-25 01:22 UTC
Frompear at 7700 dot ws
StatusBogus
PackageMDB2
PHP Version5.1.6
OSGentoo Linux
Roadmaps(Not assigned)

Comments

[2006-11-25 01:22 UTC] pear at 7700 dot ws

Description:
------------
When two separate MDB2 objects with the same username/password and host, but different databases are instantiated (using the factory() function) and then queries (using query() function, or in this case the autoExecute() function) are used on the two objects back and forth (i.e. in a loop for the purposes of copying data) then the second MDB2 object will instead of using it's own configuration information, use the first's (tested against the database specified during the factory() call).

Test script:
---------------
$SrcDB =& MDB2::factory('mysql://root@localhost/abc');
$DestDB =& MDB2::factory('mysql://root@localhost/xyz');

$Tables = Array('first', 'second', 'third');

foreach ( $Tables as $Table ) {
echo "$Table\n";

// Select everything from the table.
$sql = "SELECT * FROM `$Table`";
$DataResult =& $SrcDB->query($sql);

// Check that result is not an error
if (PEAR::isError($DataResult)) {
die($DataResult->getMessage()."\n");
}

while ($Row = $DataResult->fetchRow()) {
print_r($Row);
$affectedRows =& $DestDB->autoExecute($Table, $Row);
//print_r($affectedRows);
if (PEAR::isError($affectedRows)) {
die($affectedRows->getMessage()."\n");
}
}

$DataResult->free();
}

Expected result:
----------------
Data is successfully copied from the tables in database 'abc' to the tables in database 'xyz'.

Actual result:
--------------
The script errors out after a query that was supposed to go to database 'xyz' went to 'abc'. The problem goes away if the two factory() functions are called with different hosts specified (i.e. "localhost" and "127.0.0.1" instead of both reading as "localhost").

[2006-12-18 20:49 UTC] tristan at docutronsystems dot com

I can also verify that this is occurring with the mysql and mssql driver. It is not occurring with the pgsql driver.

[2007-01-02 17:48 UTC] tristan at docutronsystems dot com

Alright, this may help MySQL, but MSSQL does not support new_link.