|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80458 PDOStatement::fetchAll() throws for upsert queries
Submitted: 2020-12-01 19:06 UTC Modified: 2020-12-02 15:53 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:0 (0.0%)
From: php dot net dot 20 dot 12 dot 2016 at 0pe dot de Assigned:
Status: Closed Package: PDO MySQL
PHP Version: 7.4.13 OS: Arch Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php dot net dot 20 dot 12 dot 2016 at 0pe dot de
New email:
PHP Version: OS:


 [2020-12-01 19:06 UTC] php dot net dot 20 dot 12 dot 2016 at 0pe dot de
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:
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_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


Expected result:
fetch/fetchAll should return false if there is no data for the query


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-02 15:53 UTC]
-Summary: Exception thrown instead of return false +Summary: PDOStatement::fetchAll() throws for upsert queries
 [2020-12-02 22:57 UTC]
The following pull request has been associated:

Patch Name: Bug #80458 PDOStatement::fetchAll() throws for upsert queries
On GitHub:
 [2020-12-04 16:02 UTC]
Automatic comment on behalf of
Log: Fixed bug #80458
 [2020-12-04 16:02 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Oct 03 10:01:25 2023 UTC