Edit report at http://bugs.php.net/bug.php?id=53247&edit=1
ID: 53247 Comment by: rangel_wise at yahoo dot com dot br Reported by: rangel_wise at yahoo dot com dot br Summary: PDO warpped by Singleton-Factory Class does not INSERT/DELETE/ InnoDB Engine Status: Open Type: Bug Package: PDO related Operating System: Win7 - CentOS 5 PHP Version: 5.3.3 Block user comment: N New Comment: at felipe: Yes that worked, now my question is What about prepared statements over InnoDB will always require this? $stmt = Data::connect(); $stmt->beginTransaction(); $x = $stmt->prepare($q); $x->bindParam(':id', $sid); $x->bindParam(':data', $data); $x->bindParam(':expires', $time); $x->execute(); $stmt->commit(); Even is the driver is not transaction capable, and for compatibility? For SELECTs I assume it won't be necessary (beginTransaction and commit). If the answer is yes, then it's not a bug or issue, just lack of clear documentation and this case shall be closed. Previous Comments: ------------------------------------------------------------------------ [2010-11-06 16:37:26] fel...@php.net Probably you are using autocommit disabled, so the COMMIT statement is required. ------------------------------------------------------------------------ [2010-11-06 16:23:58] rangel_wise at yahoo dot com dot br Description: ------------ I've spent a couple days trying to figure why and no success so far: Wrapping PDO with a Singleton or a Factory class for easy driver switching does not INSERT/DELETE/UPDATE on MySQL InnoDB engine. SELECT statements works fine and if switch to MyISAM everything works as expected. PHP 5.3.1 up to 5.3.3 (Namespaced classes) MySQL version 5.1 (tested on all builds) Windows 7 and CentOS5 Apache 2.2 Test script: --------------- <?php namespace Subroutine; use FW\CFG; class Data{ private static $instance = NULL; public static $DRIVER = NULL; /** * @return PDO */ public static function connect(){ if (self::$instance === NULL): $username = NULL; $passwd = NULL; $options = array(); self::$DRIVER = strtolower(CFG::key()->_DB['DRIVER']); switch (self::$DRIVER): case 'mysql': $dsn = self::$DRIVER . ':host=' . CFG::key()->_DB['HOST'] . ';dbname=' . CFG::key()->_DB['SCHEMA']; $username = CFG::key()->_DB['USER']; $passwd = CFG::key()->_DB['PASS']; $options = array( CFG::key()->_DB['OPTIONS'] ); break; //Other drivers not implemented yet endswitch; try{ self::$instance = new \PDO($dsn, $username, $passwd, $options); } catch(PDOException $e){ echo $e->getMessage(); return; } endif; return self::$instance; } } ?> Expected result: ---------------- <?php namespace Model; use Subroutine\Data; class MyModel{ public function init(){ $m = Data::connect(); $m->exec("INSERT INTO sessions (id, data, expires) VALUES (123,'my data',1234567890)"); } } ?> Expects to INSERT in MySQL InnoDB engine. Actual result: -------------- Does not INSERT/DELETE/UPDATE in MySQL InnoDB. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53247&edit=1