php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77033 Incorrect exception message for diagnostic statements w emul prepares disabled
Submitted: 2018-10-18 13:09 UTC Modified: -
From: fredric dot miscmail+php at gmail dot com Assigned:
Status: Open Package: PDO MySQL
PHP Version: 7.1.23 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-10-18 13:09 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Dec 11 23:01:25 2018 UTC