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] davidc (David Coallier)
Could you please try to upgrade the mssql driver and let me know if this works please ? There is defenitivly a better handling of multiple instances now. Let me know.
 [2007-01-17 06:38 UTC] davidc (David Coallier)
Could you please try to upgrade the mssql driver and let me know if this works please ? There is defenitivly a better handling of multiple instances now. Let me know.
 [2007-01-17 06:39 UTC] davidc (David Coallier)
Sorry for the double comments my bad.
 [2007-01-17 06:53 UTC] davidc (David Coallier)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/MDB2_Driver_mssql This has been fixed in the previous release. Thanks
 [2007-06-09 17:37 UTC] quipo (Lorenzo Alberton)
Fixed for real, this time :) Please fetch the CVS version and set the 'new_link' dsn option to true.