|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-02-01 00:56 UTC] enrico_kaelert at kabelmail dot de
Description: ------------ Trying to keep it short: System: Win7 64bit, xampp (MySQL Server Version: 5.6.14 PHP Version: 5.5.6) Also tried that on a different system with (i think) PHP Version 5.8 The case: using PDO to fire more than 1 INSERT INTO via PDO::beginTransaction() and PDO::commit() The bug: if i DO NOT set $stmt to "what ever", then the PDO::commit() has no effect. But if i change $stmt to a string, a number or null - anything else but itself - then all INSERTs are fired up. Weird to describe. Just see the test script at "# 3. ..." (line 43) where the "magic" happens. To switch between the "working version" and the "bug version" simple change the if(1) to if(0) ... "bug version" $stmt is a prepared query which was just executed. Because we did a $dbh->beginTransaction(); we do now fire a $dbh->commit(); But ... no action has been taken @db - no inserts made. This only seem to happen if you fire MORE than 1 INSERT at 1 query. "working version" The ONLY different here is that we set $stmt to something else. $stmt is of curse the current prepared and executed query. Now BEFORE we fire the $dbh->commit() we do: $stmt = 'anything else'; And - its magic - the following $dbh->commit() works :: all INSERTs are done. Weird: If you look at the SELECT (# 4.) you can see that we get "fake"(?)-results back. On every run the AUTO_INCREMENT counts up which is real - so those ids get lost. Thanks for you time - coulndt do it shorter. Was looking into that problem for hours today with a friend =) Test script: --------------- detailed test script: http://pastebin.com/1QEcnPhM Expected result: ---------------- explained in the description Actual result: -------------- explained in the description PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
With the ode from 2014-04-24 12:25 UTC I get this result: Array ( [0] => Array ( [id] => 1 [name] => a ) [1] => Array ( [id] => 2 [name] => b ) [2] => Array ( [id] => 3 [name] => c ) ) This seems right to me. I tried a handful combinations of MySQL servers & PHP versions. Not on windows, though (while I can't imagine something Windows specific to be the case)@johannes Which $type you used? And did you looked into the db to make sure the entries really exists? @all btw: something new: I found out that: - if you use only 1 INSERT INTO in the query - and if you add comments to the query then the same effect happen: no INSERT made. So change the query in the test script to: # 3. multi insert via beginTransaction() and commit() / rollBack() (...) $sql = " INSERT INTO `testdb`.`tbl` SET `name` = 'a'; -- this is my comment -- this is a new line comment "; (...) Delete the test table if exists and use the $type "regular". This is only 1 INSERT INTO and should work. But it doesnt because of the comments(?). BUT it will work if we destroy the $stmt (by using the $type "alternative").edit: try this: change the query in the test script to: # 3. multi insert via beginTransaction() and commit() / rollBack() (...) $sql = " -- this is my pretty commented query ... -- above comments works INSERT INTO `testdb`.`tbl` SET `name` = 'a' -- middle comment works -- `name` = 'a' middle new line comments works ; -- but this comment finally f* it up -- so simple nothing is allowed after the ; -- except if we destroy the stmt ";