问题
Searching for the solution to my previous question I've come across a weird fact - PDO prepare() with multi-queries does not work correctly inside a transaction. You get no warning, no exception, nothing - just silence and no commit/rollback.
Furthermore, you get no exception even if some of the queries except for the first one contain errors. Although if the first query contains an error you get an exception as expected.
If there is no transaction everything works fine.
If you put several prepare() statements (with a single query each one) inside a single transaction - again, everything works correctly.
I've read that MySQL does not support prepared statements with multi-queries, but the thing is that PDO by default does not deal with real MySQL prepared statements and only emulates them.
I've spent the whole day trying to find some document describing this problem but I failed.
Does anybody know if it's really a PDO bug?
回答1:
This behavior actually is a bug on some versions (tested on PHP 5.4.6-Ubuntu and PHP 5.4.19-Windows).
There's no (easy to find) documentation about this problem, an the only workaround is to use multiple prepared statements.
Just reported the bug https://bugs.php.net/bug.php?id=65994
来源:https://stackoverflow.com/questions/9614876/pdo-bug-prepare-with-multi-queries-doesnt-work-inside-a-transaction