Bug #80458 [NEW]: Exception thrown instead of return false
From: php dot net dot 20 dot 12 dot 2016 at 0pe dot de
Operating system: Arch Linux
PHP version: 7.4.13
Package: PDO MySQL
Bug Type: Bug
Bug description:Exception thrown instead of return false
Description:
------------
Using PDOStatement::fetch() or PDOStatement::fetachAll() after a query
without resulting data (INSERT, DELETE and so on) results in throw of
PDOException.
2 problems:
1.: Before PHP 7.4.13 fetch(All) returned false. Throwing an exception
here seems wrong to me.
2.: Exception text is misleading. It says that there are other
unbuffered queries even when there are no queries made before.
Exception text: "Uncaught PDOException: 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"
Test script:
---------------
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect
$pdoLink = new PDO("mysql:dbname=test;host=localhost;charset=UTF8",
'root', 'root');
$pdoLink->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
$pdoLink->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdoLink->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
$pdoLink->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdoLink->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$pdoLink->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
$pdoLink->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
// Query
$stmt = 'INSERT INTO pdotest_user (username) VALUES
(:username)';
$pdoStmt = $pdoLink->prepare($stmt);
$pdoStmt->execute([':username' => 'Testman']);
// Result
$resArr = [];
while (($row = $pdoStmt->fetch(PDO::FETCH_ASSOC)) !== false) //
Exception thrown here
$resArr[] = $row;
// Cleanup
$pdoStmt->closeCursor();
print_r($resArr);
Expected result:
----------------
fetch/fetchAll should return false if there is no data for the query
--
Edit bug report at https://bugs.php.net/bug.php?id=80458&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80458&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80458&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80458&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80458&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80458&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80458&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80458&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80458&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80458&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80458&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80458&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80458&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80458&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80458&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80458&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80458&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80458&r=mysqlcfg
Thread (3 messages)
- php dot net dot 20 dot 12 dot 2016 at 0pe dot de