Bug #77033 [NEW]: Incorrect exception message for diagnostic statements w emul prepares disabled

From: Date: Thu, 18 Oct 2018 13:09:22 +0000
Subject: Bug #77033 [NEW]: Incorrect exception message for diagnostic statements w emul prepares disabled
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217623@lists.php.net to get a copy of this message
From:             fredric dot miscmail+php at gmail dot com
Operating system: Linux
PHP version:      7.1.23
Package:          PDO MySQL
Bug Type:         Bug
Bug description:Incorrect exception message for diagnostic statements w emul prepares disabled

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 bug report at https://bugs.php.net/bug.php?id=77033&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=77033&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=77033&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=77033&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=77033&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=77033&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=77033&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=77033&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=77033&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=77033&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=77033&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=77033&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=77033&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=77033&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77033&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=77033&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=77033&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=77033&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77033&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=77033&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=77033&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#217623) next »