Bug #80472 [Dup]: fetchAll after execute now failing on DELETE's

From: Date: Wed, 02 Dec 2020 16:03:37 +0000
Subject: Bug #80472 [Dup]: fetchAll after execute now failing on DELETE's
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230800@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80472&edit=1

 ID:                 80472
 User updated by:    dougnelson at silktide dot com
 Reported by:        dougnelson at silktide dot com
 Summary:            fetchAll after execute now failing on DELETE's
 Status:             Duplicate
 Type:               Bug
 Package:            PDO MySQL
 Operating System:   Linux (Ubuntu + Alpine tested)
 PHP Version:        7.4.13
 Block user comment: N
 Private report:     N

 New Comment:

That it is! I did look this morning so I'm not sure how I missed it!

Thanks for the quick response.


Previous Comments:
------------------------------------------------------------------------
[2020-12-02 15:54:05] nikic@php.net

Thanks for the report! This seems to be the same issue as bug #80458.

------------------------------------------------------------------------
[2020-12-02 15:51:08] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80472&edit=1


Thread (3 messages)

« previous php.bugs (#230800) next »