From: edrozenberg at pobox dot com Operating system: WindowsXP SP2 PHP version: 5.1.1 PHP Bug Type: PDO related Bug description: PDO problem with insert transaction with prepared query and currval - Postgres
Description: ------------ Created a Database class containing an insert function. The function takes an array of statements and values and executes each one within a transaction. I test it using two statements. The 2nd statement uses currval('mysequence') to insert an ID that is the same as the one generated by the first statement. Problem is the inserts do not take place, and there is also no exception raised so it looks like the transaction committed just fine. Reproduce code: --------------- Below is the function from the Database.php class: function insert($inserts) { $this->dbh->beginTransaction(); try { foreach ($inserts as $insert) { $stmt = $this->dbh->prepare($insert['query']); $stmt->execute($insert['values']); } } catch (Exception $e) { $this->dbh->rollBack(); echo "Failed: " . $e->getMessage(); return 0; } $this->dbh->commit(); return 1; } ====================================================== I call the Database.php class from here: <?php require ('./lib/Database.php'); $db = new Database(NULL); $inserts[] = array("query"=>'insert into t_company (name, url, description) values (?, ?, ?)', "values"=>array('IBM','www.ibm.com','The IBM Company')); $inserts[] = array("query"=>'insert into t_doc (company_id, doctype, private_flag) values (?, ?, ?)', "values"=>array('currval(\'t_company_company_id_seq\')','patent','f')); $db->insert($inserts) ?> Expected result: ---------------- The company IBM should be inserted into table t_company. A row should be inserted into the table t_doc with the column company_id pointing to the IBM row in t_company. -- Edit bug report at http://bugs.php.net/?id=35809&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35809&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35809&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35809&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=35809&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35809&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35809&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35809&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35809&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35809&r=support Expected behavior: http://bugs.php.net/fix.php?id=35809&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35809&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35809&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35809&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35809&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35809&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35809&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35809&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35809&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35809&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35809&r=mysqlcfg