Bug #53247 [Opn]: PDO warpped by Singleton-Factory Class does not INSERT/DELETE/ InnoDB Engine
| From: | felipe@php.net | Date: | Sat, 06 Nov 2010 15:37:29 +0000 |
| Subject: | Bug #53247 [Opn]: PDO warpped by Singleton-Factory Class does not INSERT/DELETE/ InnoDB Engine | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155805@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53247&edit=1
ID: 53247
Updated by: felipe@php.net
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:
Probably you are using autocommit disabled, so the COMMIT statement is
required.
Previous Comments:
------------------------------------------------------------------------
[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