ID: 36347
User updated by: david at acz dot org
Reported By: david at acz dot org
Status: Open
Bug Type: PDO related
Operating System: SuSE Linux 9.3
PHP Version: 5.1.2
New Comment:
This bug is similar to #34499. I can't comment on that, so I'm
commenting here:
"OPTIMIZE TABLE is a query that returns rows.
You should use PDO::query() instead.
I'll see about handling this user error more gracefully."
You actually can't use PDO::query() with OPTIMIZE TABLE:
HY000:2030:This command is not supported in the prepared statement
protocol yet
What is the solution?
Previous Comments:
------------------------------------------------------------------------
[2006-02-10 01:24:25] david at acz dot org
Description:
------------
[Note: I am actually testing this on PHP 5.1.1. If this bug was fixed
in PHP 5.1.2, please add a note to the manual page for PDO::exec()].
The manual says:
"PDO::exec() does not return results from a SELECT statement. For a
SELECT statement that you only need to issue once during your program,
consider issuing PDO::query()."
Either the manual needs to be changed, or, ideally, PDO::exec() needs
to be fixed to discard results.
This issue has bit me multiple times. It's easy to forget that a
certain query (such as MySQL's OPTIMIZE TABLE) will return a result.
Using PDO::exec() in such cases causes an error later that can be
difficult to track down.
Reproduce code:
---------------
<?
$db = new PDO("mysql:host=localhost;dbname=test");
$db->exec("SELECT 1");
$st = $db->prepare("SELECT NOW()");
if ($st === false)
{
$e = $db->errorInfo();
echo "$e[0]:$e[1]: $e[2]\n";
}
?>
Expected result:
----------------
[nothing]
Actual result:
--------------
HY000: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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36347&edit=1