From:             uwendel at mysql dot com
Operating system: Linux
PHP version:      5.3CVS-2008-02-18 (CVS)
PHP Bug Type:     PDO related
Bug description:  Errors not cleaned properly

Description:
------------
According to the manual, PDO::errorInfo() returns the error information
about the "last operation performed by this database handle",
http://www.php.net/manual/en/function.PDO-errorInfo.php

What is PDO supposed to return if you perform two operations of which the
first fails and the second works fine, like this:

[1] THIS IS NO VALID SQL, I HOPE
[2] CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp
VARCHAR(10))

Should errorInfo() return the error information from [1] or will the error
information be cleared prior to running [2]. In the latter case, the user
is given an additional easy way to check if an operation has failed or not.


And the latter case (clear info before running [2]) is what I as the
desired behaviour.

Next question: which elements of the errorInfo() element shall be reset?
Currently it seems to me as if the SQLSTATE code is reset to '00000' but
some drivers (e.g. PDO/MySQL, PDO/SQLlite, maybe more) do not reset their
driver specific fields. Haven't checked if that's an issue caused by code
from ext/pdo or from ext/pdo_mydriver. 









Reproduce code:
---------------
--TEST--
PDO Common: PDO->errorInfo(), clear line after error
--SKIPIF--
<?php # vim:ft=php
if (!extension_loaded('pdo')) die('skip');
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false)
putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory('PDO', false);

$db = PDOTest::factory('PDO', false);
@$db->exec('THIS IS NO VALID SQL, I HOPE');
var_dump($db->errorInfo());
var_dump($db->errorCode());

$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10),
grp VARCHAR(10))');
var_dump($db->errorInfo());
var_dump($db->errorCode());
print "done!";
?>
--EXPECTF--
array(3) {
  [0]=>
  string(5) "%s"
  [1]=>
  int(%d)
  [2]=>
  string(%d) "%s"
}
string(5) "%s"
array(3) {
  [0]=>
  string(5) "00000"
  [1]=>
  NULL
  [2]=>
  NULL
}
string(5) "00000"
done!

Expected result:
----------------
see above

Actual result:
--------------
see above

-- 
Edit bug report at http://bugs.php.net/?id=44151&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44151&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44151&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44151&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44151&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44151&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44151&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44151&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44151&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44151&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44151&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44151&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44151&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44151&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44151&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44151&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44151&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44151&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44151&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44151&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44151&r=mysqlcfg

Reply via email to