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: 2020-12-10 11:11 UTC
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: fredric dot miscmail+php at gmail dot com Assigned:
Status: Duplicate Package: PDO MySQL
PHP Version: 7.1.23 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
7 + 39 = ?
Subscribe to this entry?

 
 [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

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-08 16:07 UTC] hadrien dot sibboni at gmail dot com
Same issue as https://bugs.php.net/bug.php?id=70066 ? 

but there is more analysis in here?
 [2020-12-10 11:11 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2020-12-10 11:11 UTC] nikic@php.net
This is indeed (another!) duplicate of bug #70066.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC