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
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: lopez at freshsite dot de
New email:
PHP Version: OS:

 

 [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: Thu Apr 18 06:01:28 2024 UTC