Bug #69504 [NEW]: PDO::exec() returns wrong value on MySQL

From: Date: Wed, 22 Apr 2015 14:48:54 +0000
Subject: Bug #69504 [NEW]: PDO::exec() returns wrong value on MySQL
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192276@lists.php.net to get a copy of this message
From: joao dot pinheiro at weduc dot com Operating system: Linux/FreeBSD PHP version: Irrelevant Package: PDO MySQL Bug Type: Bug Bug description:PDO::exec() returns wrong value on MySQL 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 bug report at https://bugs.php.net/bug.php?id=69504&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69504&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69504&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69504&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69504&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69504&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69504&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69504&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69504&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69504&r=support Expected behavior: https://bugs.php.net/fix.php?id=69504&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69504&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69504&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69504&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69504&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69504&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69504&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69504&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69504&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69504&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69504&r=mysqlcfg

« previous php.bugs (#192276) next »