|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61516 PDOStatement::errorInfo returning NULL for driver code and message
Submitted: 2012-03-26 16:49 UTC Modified: 2014-01-01 12:39 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: julien at palard dot fr Assigned:
Status: Open Package: PDO MySQL
PHP Version: 5.4.0 OS: Linux 2.6.32-5-amd64
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 — but make sure to vote on the bug!
Your email address:
Solve the problem:
43 + 39 = ?
Subscribe to this entry?

 [2012-03-26 16:49 UTC] julien at palard dot fr
While using not emulated prepared statement against MySQL 5.5, warnings (using ERRMODE_WARNING) are more verbose than errorInfo(). With prepared queries, errorInfo return (string, NULL, NULL).

This fact is true with or without ERRMODE_WARNING.

And this fact is also true, but different while using standard queries :

What the warning give me :
[WARNING] PDO::query() [<a href='pdo.query'>pdo.query</a>]: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '83-27
7727' for key 'UNIQUE'

What I got from errorInfo()[2] (Missing the "Integrity constraint violation:" string, built client side from error code ?) :
Duplicate entry '83-277727' for key 'UNIQUE'

Test script:

class My_PDOStatement extends PDOStatement
    public function execute($input_parameters = NULL)
        $res = parent::execute($input_parameters);
        if ($res === FALSE)
        return $res;

$options = array(PDO::ATTR_PERSISTENT => FALSE,
                 PDO::ATTR_STATEMENT_CLASS => array('My_PDOStatement'));

$pdo = new PDO(...);

$stmt = $pdo->prepare("SELECT :a + :a");
$stmt->execute(array('a' => 1)); // Willingly generate 'Invalid parameter number'

Expected result:
I Expect errorInfo() to return error messages.

Actual result:
errorInfo() in this specific case return (string, NULL, NULL).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-30 16:39 UTC]
The PDO warning is based on a static look-up table compiled into the PDO core. That means, it is out of control of any PDO driver. A SQL code reported by a driver is translated into whatever message the PDO core likes.

Any PDO driver is free to provide an internal callback to update the contents of the return value of errorInfo(). Providing an internal callback is not mandatory.

Due to the different source of the error message one must not expect error messages to be equal. At the end of the day: this is PDO...
 [2012-05-02 09:51 UTC] julien at palard dot fr, I think that one can expect to have as much as possible informations about an error, and that it's not fair to provide different level of precision to one querying the error description from one way.

Just think about those who just didn't spotted the difference or those who simply don't want to use ERRMODE_WARNING, they will have harder times to fix their SQL bugs, that's not a good thing. I personally think this should be fixed.
 [2014-01-01 12:39 UTC]
-Package: PDO related +Package: PDO MySQL
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 18:01:33 2024 UTC