php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53247 PDO warpped by Singleton-Factory Class does not INSERT/DELETE/ InnoDB Engine
Submitted: 2010-11-06 16:23 UTC Modified: 2010-11-06 17:31 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rangel_wise at yahoo dot com dot br Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.3.3 OS: Win7 - CentOS 5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rangel_wise at yahoo dot com dot br
New email:
PHP Version: OS:

 

 [2010-11-06 16:23 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-06 16:37 UTC] felipe@php.net
Probably you are using autocommit disabled, so the COMMIT statement is required.
 [2010-11-06 17:18 UTC] rangel_wise at yahoo dot com dot br
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.
 [2010-11-06 17:31 UTC] felipe@php.net
-Status: Open +Status: Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 03:01:29 2024 UTC