Bug #69504 [Opn->Nab]: PDO::exec() returns wrong value on MySQL

From: Date: Fri, 11 Dec 2020 14:59:51 +0000
Subject: Bug #69504 [Opn->Nab]: PDO::exec() returns wrong value on MySQL
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231021@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69504&edit=1 ID: 69504 Updated by: nikic@php.net Reported by: joao dot pinheiro at weduc dot com Summary: PDO::exec() returns wrong value on MySQL -Status: Open +Status: Not a bug Type: Bug Package: PDO MySQL Operating System: Linux/FreeBSD PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Behavior is the same on MySQL CLI, as such this has no relation to PDO (or PHP at all). If you think this behavior is not correct, then you need to report it with the MySQL project. Previous Comments: ------------------------------------------------------------------------ [2015-04-22 14:48:54] joao dot pinheiro at weduc dot com Description: ------------ Calling MySQL's PDO::exec() with an update query that doesn't change existing data on an existing row always returns 0. With PostgreSQL, always returns 1. If, in MySQL, a trigger is added to the updating table, the trigger is executed (and inserts may occur) but the result is still 0. I am aware of the differences between Postgresql and Mysql regarding updates due to MVCC, but if a trigger changes something, it should return the number of affected rows. Test script: --------------- /* Assuming the following sql structure: create table test( id int(11) not null, name varchar(128) not null ); insert into test values(1, 'test_name'); */ $query = "update test set name='xpto' where id=1"; echo $pdo->exec($query); // first run returns 1, all others 0 /* Add the following trigger: create table control( counter int(11) not null ); insert into control values(0); CREATE TRIGGER test_update BEFORE UPDATE ON test FOR EACH ROW BEGIN UPDATE control set counter=counter+1; END$$ */ $query = "update test set name='xpto' where id=1"; echo $pdo->exec($query); // first run returns 1, all others 0, but control table is updated ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69504&edit=1

« previous php.bugs (#231021) next »