Bug #61516 [Opn]: PDOStatement::errorInfo returning NULL for driver code and message

From: Date: Mon, 30 Apr 2012 16:39:38 +0000
Subject: Bug #61516 [Opn]: PDOStatement::errorInfo returning NULL for driver code and message
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-170039@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61516&edit=1

 ID:                 61516
 Updated by:         uw@php.net
 Reported by:        julien at palard dot fr
 Summary:            PDOStatement::errorInfo returning NULL for driver
                     code and message
 Status:             Open
 Type:               Bug
 Package:            PDO related
 Operating System:   Linux 2.6.32-5-amd64
 PHP Version:        5.4.0
 Block user comment: N
 Private report:     N

 New Comment:

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...


Previous Comments:
------------------------------------------------------------------------
[2012-03-26 16:49:00] julien at palard dot fr

Description:
------------
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:
---------------
<?php

class My_PDOStatement extends PDOStatement
{
    public function execute($input_parameters = NULL)
    {
        $res = parent::execute($input_parameters);
        if ($res === FALSE)
            var_dump($this->errorInfo());
        return $res;
    }
}

$options = array(PDO::ATTR_PERSISTENT => FALSE,
                 PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
                 PDO::ATTR_EMULATE_PREPARES => FALSE,
                 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                 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'
var_dump($stmt->fetchAll());


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

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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61516&edit=1


Thread (3 messages)

« previous php.bugs (#170039) next »