Bug #77033 [Com]: Incorrect exception message for diagnostic statements w emul prepares disabled
| From: | hadrien dot sibboni at gmail dot com | Date: | Tue, 08 Oct 2019 16:07:05 +0000 |
| Subject: | Bug #77033 [Com]: Incorrect exception message for diagnostic statements w emul prepares disabled | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223144@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77033&edit=1
ID: 77033
Comment by: hadrien dot sibboni at gmail dot com
Reported by: fredric dot miscmail+php at gmail dot com
Summary: Incorrect exception message for diagnostic
statements w emul prepares disabled
Status: Open
Type: Bug
Package: PDO MySQL
Operating System: Linux
PHP Version: 7.1.23
Block user comment: N
Private report: N
New Comment:
Same issue as https://bugs.php.net/bug.php?id=70066 ?
but there is more analysis in here?
Previous Comments:
------------------------------------------------------------------------
[2018-10-18 13:09:22] fredric dot miscmail+php at gmail dot com
Description:
------------
When running the following script against a mysql 5.7 server, the query() call will throw an
exception with an incorrect and confusing message: "...General error: 2014 Cannot execute
queries while other unbuffered queries are active....".
What mysql returns is (see strace below) "#HY000This command is not supported in the prepared
statement protocol yet" which is consistent with the documentation regarding diagnostic
statements: https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-prepared-statements.html
Turning on emulated prepares for "SHOW WARNINGS" allows it to run
strace:
<snip>
sendto(3, "\16\0\0\0\26SHOW WARNINGS", 18, MSG_DONTWAIT, NULL, 0) = 18
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "M\0\0\1\377\17\5#HY000This command is not supported in the prepared statement
protoc", 75, MSG_DONTWAIT, NULL, NULL) = 75
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "ol yet", 82, MSG_DONTWAIT, NULL, NULL) = 6
write(1, "0: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered
queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only
ever going to run against mysql, you may enable query buffering by setting the
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. line: 7\n", 3180: SQLSTATE[HY000]: General error:
2014 Cannot execute queries while other unbuffered queries are active. Consider using
PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you
may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. line: 7
) = 318
sendto(3, "\1\0\0\0\1", 5, MSG_DONTWAIT, NULL, 0) = 5
<snip>
Test script:
---------------
<?php
$pdo = new PDO('mysql:host=localhost', 'user', 'password');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$pdo->query("SHOW WARNINGS");
} catch (Exception $e) {
printf("%d: %s line: %d\n", $e->getCode(), $e->getMessage(), $e->getLine());
}
Expected result:
----------------
A more correct exception message. MySQL returns "#HY000This command is not supported in the
prepared statement protocol yet"
Actual result:
--------------
0: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are
active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to
run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY
attribute. line: 7
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77033&edit=1