php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80510 Error is Thrown on fetchAll on Update and Insert
Submitted: 2020-12-13 11:27 UTC Modified: 2020-12-13 11:40 UTC
From: max dot kaufmann at 1000eyes dot org Assigned:
Status: Duplicate Package: PDO MySQL
PHP Version: 7.4.13 OS: Ubuntu 20.04, Windows 10
Private report: No CVE-ID: None
 [2020-12-13 11:27 UTC] max dot kaufmann at 1000eyes dot org
Description:
------------
This Bugs happens in Version 7.4.13 and 8.0.0.

You also need to Create a Table like:
CREATE TABLE tabba (id int AUTO_INCREMENT, name varchat(32) NOT NULL);

And insert something in it:
INSERT INTO tabba (name) VALUES ("Franc");

It is possible to remove the Error an go back to expected behavior when removing "PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION".
But is more or less only a workaround.

This Bug break functions like Query which creates an PDO Statement and returns an array of the fetchAll result.

Test script:
---------------
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$_Host = '127.0.0.1';
$_Port = 3306;
$_Database = 'test';
$_Charset = 'utf8mb4';
$_DriverOptions =
    [
        PDO::ATTR_EMULATE_PREPARES => false,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
    ];

$iDSN = 'mysql:dbname=' . $_Database . ';host=' . $_Host . ';port=' . $_Port . ';charset=' . $_Charset;
var_dump($iDSN);
$_Hash = hash('sha512', $iDSN);

try {
    $_ObjDb = new PDO($iDSN, 'dbuser', 'dbpassword', $_DriverOptions);
} catch (Exception $e) {
    var_dump($e);
    exit('Connection to database failed.');
}

$iStatement = $_ObjDb->prepare('UPDATE tabba SET name=:name WHERE id = 1');
$iName = 'Frank';
$iStatement->bindParam(':name', $iName);


try {
    var_dump($iStatement->execute());
}
catch(PDOException $e) {
    die($e->getMessage());
}

var_dump($iStatement->rowCount());
if ($iStatement->rowCount() > 0) {
    var_dump($iStatement->fetchAll());
}


Expected result:
----------------
In version 7.4.12 and older fetchAll() would return an empty array.

Actual result:
--------------
Returns an Error that something is unbuffered.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-13 11:40 UTC] dharman@php.net
-Status: Open +Status: Duplicate
 [2020-12-13 11:40 UTC] dharman@php.net
Duplicate of 80458. 
The issue was that there is no result returned from MySQL for INSERT/UPDATE queries. Trying to fetch the result would throw an error using emulated prepared statements already, but given that people expect an empty result we fixed both in 7.4.14 to return an empty array if there are no results.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC