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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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: Wed May 01 09:01:30 2024 UTC