php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69504 PDO::exec() returns wrong value on MySQL
Submitted: 2015-04-22 14:48 UTC Modified: -
From: joao dot pinheiro at weduc dot com Assigned:
Status: Open Package: PDO MySQL
PHP Version: Irrelevant OS: Linux/FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joao dot pinheiro at weduc dot com
New email:
PHP Version: OS:

 

 [2015-04-22 14:48 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Nov 27 23:01:24 2020 UTC