php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53970 PDOStatement::execute returns TRUE even when sql statement is not executed
Submitted: 2011-02-09 12:04 UTC Modified: 2012-05-04 16:14 UTC
From: lopez at freshsite dot de Assigned:
Status: Not a bug Package: PDO related
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
27 - 13 = ?
Subscribe to this entry?

 
 [2011-02-09 12:04 UTC] lopez at freshsite dot de
Description:
------------
I recognized, that the return value stay TRUE, even if the sql statement could not be executed correctly.

Test script:
---------------
Example:
$sth = $this->db->prepare("REPLACE INTO test
				                                    SET bar = :foo);
$error = $sth->execute(array('foo' => 'bar'));

/*
$error will be TRUE, because sql is correct and sent.

However, if the mysql user has not the rights (INSERT,DELETE) to do this, the statement will be not executed at all without error message.

So, don't rely on the returning value until this is fixed!

Expected result:
----------------
$error should be FALSE

Actual result:
--------------
$error is TRUE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-09 13:44 UTC] lopez at freshsite dot de
I recognized, that the error was different, but the expected result is same.

The sql statement tried to insert a too long string (6 chars) into a too small field => varchar(2).

However, the execute function should return FALSE, but it doesn't !
 [2012-05-04 16:14 UTC] uw@php.net
There's no error when using MySQL defaults, just a warning.
See http://dev.mysql.com/doc/refman/5.6/en/server-sql-mode.html and set sql_mode accordingly to get an error.
 [2012-05-04 16:14 UTC] uw@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 12:01:31 2024 UTC