Bug #80510 [Opn->Dup]: Error is Thrown on fetchAll on Update and Insert

From: Date: Sun, 13 Dec 2020 11:40:19 +0000
Subject: Bug #80510 [Opn->Dup]: Error is Thrown on fetchAll on Update and Insert
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231056@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80510&edit=1 ID: 80510 Updated by: dharman@php.net Reported by: max dot kaufmann at 1000eyes dot org Summary: Error is Thrown on fetchAll on Update and Insert -Status: Open +Status: Duplicate Type: Bug Package: PDO MySQL Operating System: Ubuntu 20.04, Windows 10 PHP Version: 7.4.13 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2020-12-13 11:27:26] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80510&edit=1

« previous php.bugs (#231056) next »