php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #35202 errorCode() Returns String
Submitted: 2005-11-12 20:11 UTC Modified: 2005-11-14 10:21 UTC
From: lists at zaunere dot com Assigned: wez (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.1.0RC4 OS: Windows XP
Private report: No CVE-ID: None
 [2005-11-12 20:11 UTC] lists at zaunere dot com
Description:
------------
The errorCode() method of both the PDO and PDOStatement objects return a string, rather than an integer, as documented.  If there is no error, they return an empty string.

Reproduce code:
---------------
$stmt = $MyPDO->prepare('SELECT * FROM MyTable');
var_dump($stmt->errorCode());

Expected result:
----------------
int(0)

Actual result:
--------------
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-12 20:13 UTC] helly@php.net
SQL error codes are strings
 [2005-11-13 13:37 UTC] wez@php.net
errorCode() returns a SQLSTATE string, as documented.
Use errorInfo() to obtain driver specific error information.
 [2005-11-14 04:18 UTC] lists at zaunere dot com
The function prototypes in both of these locations is wrong:

http://us2.php.net/manual/en/function.pdo-errorcode.php
http://us2.php.net/manual/en/function.pdostatement-errorcode.php

Integers are not returned as indicated in the documented function prototypes.

Furthermore, there is some inconsistency in how '00000' is returned.  It would be expected that '00000' is always returned, or that an invalid statement prepare would return an error.

Code
----

$pdo = new PDO('mysql:dbname=oet;host=localhost','me','you');
echo '    new pdo (good connection)=> ';
var_dump($pdo->errorCode());


$stmt = $pdo->prepare('SELECT * FROM Valid');
echo '   stmt prepare (valid table)=> ';
var_dump($stmt->errorCode());

$stmt->execute();
echo '   stmt execute (valid table)=> ';
var_dump($stmt->errorCode());


$stmt1 = $pdo->prepare('SELECT * FROM Invalid');
echo 'stmt1 prepare (invalid table)=> ';
var_dump($stmt1->errorCode());

$stmt1->execute();
echo 'stmt1 execute (invalid table)=> ';
var_dump($stmt1->errorCode());


$stmt2 = $pdo->prepare('INVALID SQL');
echo '  stmt2 prepare (invalid SQL)=> ';
var_dump($stmt2->errorCode());

$stmt2->execute();
echo '  stmt2 execute (invalid SQL)=> ';
var_dump($stmt2->errorCode());


Output
------

    new pdo (good connection)=> string(5) "00000"
   stmt prepare (valid table)=> string(0) ""
   stmt execute (valid table)=> string(5) "00000"
stmt1 prepare (invalid table)=> string(0) ""
stmt1 execute (invalid table)=> string(5) "HY000"
  stmt2 prepare (invalid SQL)=> string(0) ""
  stmt2 execute (invalid SQL)=> string(5) "HY000"

Only the execute() appears to set errorCode(), whereas the documents say "the last operation on the statement handle."

Thanks,

Hans
 [2005-11-14 10:21 UTC] tony2001@php.net
Fixed in CVS, will appear after the next docu build.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 14:01:30 2024 UTC