php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44151 Errors not cleaned properly
Submitted: 2008-02-18 16:51 UTC Modified: 2009-02-28 14:47 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: uwendel at mysql dot com Assigned: davidc (profile)
Status: No Feedback Package: PDO related
PHP Version: 5.3CVS-2008-02-18 (CVS) OS: Linux
Private report: No CVE-ID: None
 [2008-02-18 16:51 UTC] uwendel at mysql dot com
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-17 18:05 UTC] davidc@php.net
Could you please test with the latest CVS or snapshot please? I have made a few changes related to that lately and I'm wondering if that could have fixed it.

Thanks,
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 16:01:31 2024 UTC