1
votes

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
"PDO by default does not deal with real MySQL prepared statements and only emulates them" - No, PDO abstracts parameter handling into a common syntax. The underlying DB engine (be it MySQL or any other one) must still support the features you're trying to use. - Tomalak
@Tomalak: actually OP is right - PDO emulates prepareds. "The underlying DB engine must still support the features you're trying to use" - what would it change? - zerkms
Thanks for your comment. May be I've used not the right term but still the problem exists - prepare() with multi-queries does not work within a transaction. And works when not within a transaction. - Placido
Yeah, never mind. That was overly nitpicky. - Tomalak

1 Answers

1
votes

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