Home » Database » MDB2 » Bug #8548
db connection confusion with 2 dbs same user/pass/host
Details
| Submitted | 2006-08-24 04:05 UTC |
|---|---|
| From | little dot 129 at osu dot edu |
| Status | Bogus |
| Package | MDB2 |
| PHP Version | 5.0.5 |
| OS | Ubuntu Linux |
| Roadmaps | (Not assigned) |
Comments
[2006-08-24 04:05 UTC] little dot 129 at osu dot edu
Description:
------------
I was trying to move import data from one database to another using MDB2 (for the first time). MDB2 appears to sometimes get confused as to which database it should be talking to when using the same user/pass/host but different db. Eg, I would query db1, insert to db2, and find the inserted records had somehow ended up in db1.
At first I assumed I was in error, but changing the second connection string to use an ip address host instead of localhost solved the problem.
Hopefully I'm not doing something stupid... I'm a novice with the library and this is also my first bug report.
Test script:
---------------
<?
/*
CREATE DATABASE mdb2;
USE mdb2;
CREATE TABLE `mdb2`.`test` (
`name` VARCHAR(255) DEFAULT ''
)
ENGINE = MYISAM;
CREATE DATABASE mdb2other;
USE mdb2;
CREATE TABLE `mdb2`.`test` (
`name` VARCHAR(255) DEFAULT ''
)
ENGINE = MYISAM;
*/
require_once('MDB2.php');
// Let $dsn1 be a connection string to mdb2
$dsn1 = "mysql://little:pass@localhost/mdb2";
// Let $dsn2 be a connection string to mdb2other (same user/pass/host
$dsn2 = "mysql://little:pass@localhost/mdb2other";
// Connect to all dsns
$db1 =& MDB2::factory($dsn1);
if (PEAR::isError($db1)) {
die($db1->getMessage());
}
$db2 =& MDB2::factory($dsn2);
if (PEAR::isError($db2)) {
die($db2->getMessage());
}
// Load extended - makes it easier for me being new to the lib
$db1->loadModule('Extended');
$db2->loadModule('Extended');
// Perform a query of db1
$result = $db1->getAll('select * from test');
print_r($result);
/* Output
Array
(
)
*/
// Do an insert into db2
$rowToInsert = array('name' => 'bunnies');
$db2->autoExecute('test', $rowToInsert, MDB2_AUTOQUERY_INSERT);
// Perform a query of db1
// Since we inserted into db2, this should print the same as before
// but it doesn't.
$result = $db1->getAll('select * from test');
print_r($result);
/* Output
Array
(
[0] => Array
(
[0] => bunnies
)
}
*/
/*
If you change the "localhost" part of ONE of the DSN's to something
like an IP address, you don't get this problem.
*/
?>
Expected result:
----------------
I expect the output of both print statements should be the same as no data should have been inserted into the first db.
Actual result:
--------------
The second query of db1 actually executes against db2 and so it looks like more records are inserted.
[2006-08-24 04:08 UTC] little dot 129 at osu dot edu
should be "mdb2other" in the second set of mysql commands below