|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-02-10 02:34 UTC] david at acz dot org
[2006-02-10 15:18 UTC] tony2001@php.net
[2006-02-14 15:13 UTC] iliaa@php.net
[2006-02-14 16:05 UTC] david at acz dot org
[2006-02-16 16:23 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
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.