PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » MDB2 » Bug #10033

Factory beginTransaction does not know server abilities

Details

Submitted2007-02-06 06:26 UTC
Fromsubwolf at gmail dot com
Assignedquipo
StatusClosed
PackageMDB2
PHP Version5.2.0
OSDebian Etch
Roadmaps(Not assigned)

Comments

[2007-02-06 06:26 UTC] subwolf at gmail dot com

Description:
------------
I spent a good while this evening trying to figure out why my attempts to successfully begin and then roll back a transaction were failing, using the latest stable release with the mysqli plugin. This affects the mysql plugin also.

If you utilize MDB2::factory to instantiate a database object, and immediately follow it with a call to beginTransaction(), "SET AUTOCOMMIT = 1" is issued to the MySQL server instead of "START TRANSACTION".

By default, the driver class property start_transaction is set to FALSE, and only changes if the server version matches upon connect - which won't happen with a factory instance until a query is issued.

In this scenario, beginTransaction checks $this->start_transaction before a connection is initiated, and issues the wrong query - see test scripts. Even if the server were set by default that auto-commit mode is off, the query sent would turn it back on.

This could be fixed with a connection check like _doQuery performs (and save a re-check by passing the $connection along), or for now as simple as a note in the documentation, indicating a connection must be established first.

Test script:
---------------
Simple test:

$dsn = "mysqli://username:password@host/dbname";
$db =& MDB2::factory($dsn); // Init with factory
$db->beginTransaction(); // Returns MDB2_OK

echo $db->last_query; // "SET AUTOCOMMIT = 1"

--| MDB2/Driver/mysqli.php:229-230 |--
$query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1';
$result =& $this->_doQuery($query, true);
---- ----

Expected result:
----------------
$db->last_query should contain "START TRANSACTION", and subsequent queries would be within that transaction, which could then be committed or rolled back.

Actual result:
--------------
$db->last_query contains "SET AUTOCOMMIT = 1", a transaction is not initiated, and subsequent queries cannot be committed or rolled back.

[2007-02-06 06:41 UTC] subwolf at gmail dot com

I failed to mention that the server is MySQL V5.0.27, and the tables used during testing were of type InnoDB.

(Possible duplicate comment, where'd the original go!)