#36347 [NEW]: PDO::exec() fails if the query returns results
From: david at acz dot org
Operating system: SuSE Linux 9.3
PHP version: 5.1.2
PHP Bug Type: PDO related
Bug description: PDO::exec() fails if the query returns results
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 bug report at http://bugs.php.net/?id=36347&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36347&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36347&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36347&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36347&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=36347&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36347&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36347&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36347&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36347&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36347&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=36347&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=36347&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36347&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36347&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36347&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36347&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36347&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36347&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36347&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36347&r=mysqlcfg
Thread (6 messages)
- david at acz dot org