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

Bug #10033 Factory beginTransaction does not know server abilities
Submitted: 2007-02-06 06:26 UTC
From: subwolf at gmail dot com Assigned: quipo
Status: Closed Package: MDB2 (version 2.3.0)
PHP Version: 5.2.0 OS: Debian Etch
Roadmaps: (Not assigned)    

 [2007-02-06 06:26 UTC] subwolf at gmail dot com (Rob Beckett)
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!)
 [2007-02-08 09:39 UTC] quipo (Lorenzo Alberton)
This bug should be fixed in CVS. Please fetch the updated files and reopen the bug report if it still doesn't work.