Edit report at https://pear.php.net/bugs/bug.php?id=20379&edit=1
ID: 20379
Comment by: [email protected]
Reported By: nik600 at gmail dot com
Summary: transaction not working with multiple instance of
MDB2 connections
Status: Open
Type: Bug
Package: MDB2_Driver_mysql
Operating System: Linux
Package Version: 1.4.1
PHP Version: Irrelevant
Roadmap Versions:
New Comment:
the bug affects both mysql and mysqli drivers, my patch is for mysql
driver
Previous Comments:
------------------------------------------------------------------------
[2014-08-29 11:35:02] nik600
Added #patch
bug:20379;patch:fix_multiple_connections_transaction.pat;revision:1409308502;.
------------------------------------------------------------------------
[2014-08-29 11:23:15] nik600
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:[email protected]/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
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=20379&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.