php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80472 fetchAll after execute now failing on DELETE's
Submitted: 2020-12-02 15:51 UTC Modified: 2020-12-02 16:03 UTC
From: dougnelson at silktide dot com Assigned:
Status: Duplicate Package: PDO MySQL
PHP Version: 7.4.13 OS: Linux (Ubuntu + Alpine tested)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dougnelson at silktide dot com
New email:
PHP Version: OS:

 

 [2020-12-02 15:51 UTC] dougnelson at silktide dot com
Description:
------------
A caveat that the code being here isn't ideal, but this has caused a BC and some unexpected prod problems.

If you run a delete query using PDO-MySQL in the format:

$statement->prepare($query)
$statement->execute()
$statement->fetchAll()

You previously would not encounter any issues, this exists in some generalised "run this sql" code.

As of PHP 7.4.13, this will now throw an error "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"

This also fails on PHP 8, but as that lies over a BC boundary, that seems reasonable.

Test script:
---------------
script.php
<?php
$pdo = new \PDO("mysql:host=my-hostname;dbname=testcase", "username", "password, [
    PDO::ATTR_EMULATE_PREPARES => false,
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

$pdo->exec("DROP TABLE IF EXISTS users");
$pdo->exec("CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY,name TEXT)");

$sql = "DELETE FROM `users`";
$statement = $pdo->prepare($sql);
print_r($statement->execute());
print_r($statement->fetchAll());

run.sh:
#!/usr/bin/env sh
docker-php-source extract
docker-php-ext-install pdo_mysql
php script.php

command to isolate it as 12 vs 13:
docker run -it -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.4.12-cli-alpine ./run.sh
docker run -it -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.4.13-cli-alpine ./run.sh

Expected result:
----------------
I'd expect it to not throw an error.

Actual result:
--------------
It throws an error

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-02 15:54 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2020-12-02 15:54 UTC] nikic@php.net
Thanks for the report! This seems to be the same issue as bug #80458.
 [2020-12-02 16:03 UTC] dougnelson at silktide dot com
That it is! I did look this morning so I'm not sure how I missed it!

Thanks for the quick response.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC