Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0b4

Bug #9735 Two instances fail to keep different databases selected
Submitted: 2007-01-04 20:32 UTC
From: pete at digitalhill dot com Assigned: quipo
Status: Closed Package: MDB2_Driver_mssql (version 1.1.0)
PHP Version: 4.4.4 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2007-01-04 20:32 UTC] pete at digitalhill dot com (Pete Gilbert)
Description: ------------ Two separate instances of a MDB2 object end up using the same connection resource when created. This results in the database name check in MDB2_Driver_mssql::_do_query() failing to notice that the currently selected database is no longer selected when one alternates queries from the two objects. This naturally results in tables not being found and the like. Test script: --------------- //approximation of the problem require_once('PEAR.php'); require_once('MDB2.php'); $dsn_one['username'] = "foo"; $dsn_one['password'] = "bar"; $dsn_one['hostspec'] = "remote_machine"; $dsn_one['phptype'] = 'mssql'; $db_one =& MDB2::factory($dsn_one); //connect $db_one->setDatabase('database_one'); //select one database for this connection $db_one->setFetchMode(MDB2_FETCHMODE_ASSOC); //we like hashes, ordered arrays require thinking $dsn_two['username'] = "foo"; $dsn_two['password'] = "bar"; $dsn_two['hostspec'] = "remote_machine"; $dsn_two['phptype'] = 'mssql'; $db_two =& MDB2::factory($dsn_two); //connect $db_two->setDatabase('database_two'); //select two database for this connection $db_two->setFetchMode(MDB2_FETCHMODE_ASSOC); //we like hashes, ordered arrays require thinking $res1 = $db_one->query("SELECT * FROM table_in_database_one WHERE id = 1"); //works $res2 = $db_two->query("SELECT * FROM table_in_database_two WHERE other_id = 2"); //works, as db_two still has '' for variable connection_database_name and so it performs the mssql_select_db $res1 = $db_one->query("SELECT * FROM table_in_database_one WHERE id = 3"); //fails //my fix was to replace line 289: $this->connected_database_name = ''; //with two lines: if(!isset($GLOBALS['__MDB2_mssql_connection_database_name'])) { $GLOBALS['__MDB2_mssql_connection_database_name'] = ''; } $this->connected_database_name =& $GLOBALS['__MDB2_mssql_connection_database_name']; //using a global might not be the best solution, a static variable or method might be better, but this solved my immediate issue. Expected result: ---------------- I would expect that the connections would track the selected database successfully, or just use different connections (although there is a limit). Admittedly the situation isn't ideal data organization, but sometimes things just end up that way, so we have to deal with it.

Comments

 [2007-01-17 06:38 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2007-01-17 06:38 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2007-01-17 06:39 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2007-01-17 06:53 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2007-06-09 17:37 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!