From: p dot volk at veb-it dot de
Operating system: Linux 2.6.18-4-k7
PHP version: 5.2.1
PHP Bug Type: PDO related
Bug description: PDOException->getCode() returns string
Description:
------------
PDOException->getCode() returns string instead integer.
I've tested this code with php 5.2.1 and PHP 5.2.2RC2-dev (cli) (built:
Apr 12 2007 17:17:02), from php5.2-200704121430.tar.bz2.
Reproduce code:
---------------
<?php
error_reporting(8191);
$db = new PDO('mysql:dbname=testdb;host=ahost', 'me', 'phpRulez');
#$db = new PDO('pgsql:dbname=testdb;host=ahost', 'me', 'phpRulez');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$data = array(array('php', 'rulez'), array('php', 'rulez'));
$stmt = $db->prepare('INSERT INTO atable VALUES (?, ?)');
$stmt->bindParam(1, $lang, PDO::PARAM_STR);
$stmt->bindParam(2, $action, PDO::PARAM_STR);
foreach($data as $set) {
$lang = $set[0];
$action = $set[1];
try { $stmt->execute(); }
catch (PDOException $e) {
if ($e->getCode() === 23000 || 23505 === $e->getCode())
continue;
else var_dump($e->getCode()); print $e->getMessage()."\n";
}
}
$db = null;
?>
Expected result:
----------------
No Output AND PDOException->getCode() returns an integer.
Actual result:
--------------
* PsotgreSQL
string(5) "23505"
SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key violates unique
constraint "pkey_atable"
* MySQL
string(5) "23000"
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
'php-rulez' for key 1
--
Edit bug report at http://bugs.php.net/?id=41064&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=41064&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=41064&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=41064&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41064&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=41064&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41064&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41064&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41064&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41064&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41064&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=41064&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=41064&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41064&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41064&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41064&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41064&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41064&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41064&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41064&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41064&r=mysqlcfg