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

Bug #20379 transaction not working with multiple instance of MDB2 connections
Submitted: 2014-08-29 15:23 UTC
From: nik600 Assigned:
Status: Open Package: MDB2_Driver_mysql (version 1.4.1)
PHP Version: Irrelevant OS: Linux
Roadmaps: (Not assigned)    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 14 - 7 = ?

 
 [2014-08-29 15:23 UTC] nik600 (Mosca Nicola)
Description: ------------ As shown in the test, if you want to use transactions having multiple mdb2 instances these doesn't works. This happends because in the method _getServerCapabilities() there is a static variable to avoid multiple checks to the serverCapabilities... and this is ok BUT in the constructor of the class you set a default value to false for $this->start_transaction to false. So, the first time the $this->start_transaction is set to false, then the method _getServerCapabilities set it to true, and the transaction start correctly. The second time the start_transaction is set to false again, but the metod _getServerCapabilities doesn't check as already_checked is true, and as start_transaction is set to false the metod beginTransaction does a SET AUTOCOMMIT = 1 instead of a START TRANSACTION To fix the problem you can use an attribute of the class instead of a static variable. Test script: --------------- <?php include ("MDB2.php"); /* * sql for creating the table: * CREATE TABLE IF NOT EXISTS `foo_table` ( `foo_field` int(11) NOT NULL) ENGINE=InnoDB; */ $connstring="mysql://root:mypass@127.0.0.1/test?new_link=true"; $mdb2 =& MDB2::connect($connstring); $mdb2->beginTransaction(); $mdb2->query("INSERT INTO foo_table (foo_field) VALUES ('1')"); $mdb2->rollback(); $mdb3 =& MDB2::connect($connstring); $mdb3->beginTransaction(); $mdb3->query("INSERT INTO foo_table (foo_field) VALUES ('2')"); $mdb3->rollback(); ?> Expected result: ---------------- no rows must be insert into the table Actual result: -------------- the row with value 2 is insert into the table

Comments

 [2014-08-29 15:35 UTC] nik600 (Mosca Nicola)
 [2014-08-30 01:20 UTC] nik600 (Mosca Nicola)
the bug affects both mysql and mysqli drivers, my patch is for mysql driver