Bug #74912 [NEW]: PDO errorInfo 1062 Duplicate entry

From: Date: Wed, 12 Jul 2017 16:02:40 +0000
Subject: Bug #74912 [NEW]: PDO errorInfo 1062 Duplicate entry
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210022@lists.php.net to get a copy of this message
From: marc dot w dot hagen at gmail dot com Operating system: Debian 3.2.86-1 x86_64 PHP version: 5.6.31 Package: PDO related Bug Type: Bug Bug description:PDO errorInfo 1062 Duplicate entry Description: ------------ PDOStatement->errorInfo() will have driver errors even if there is a new query that has been executed. If, for example, there is a duplicated query on the first statement it will return false and populates the errorInfo. But the next query that succeeds still has the errorInfo, only array key 1 and 2, from the previous query. This should be cleared. Test script: --------------- <?php $db = new PDO("mysql:host=".$dboptions['host'].";port=".$dboptions['port'].";dbname=".$dboptions['dbname'], $dboptions['username'], $dboptions['password']); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $data = [ [ 'php', 'rulez' ], [ 'php', 'rulez' ], [ 'php', 'rule' ] ]; $stmt = $db->prepare('INSERT INTO testTable 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]; $stmt->execute(); var_dump($stmt->errorInfo()); } $db = null; Expected result: ---------------- array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL } array(3) { [0]=> string(5) "23000" [1]=> int(1062) [2]=> string(45) "Duplicate entry 'php-rulez' for key 'PRIMARY'" } array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL } Actual result: -------------- array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL } array(3) { [0]=> string(5) "23000" [1]=> int(1062) [2]=> string(45) "Duplicate entry 'php-rulez' for key 'PRIMARY'" } array(3) { [0]=> string(5) "00000" [1]=> int(1062) [2]=> string(45) "Duplicate entry 'php-rulez' for key 'PRIMARY'" } -- Edit bug report at https://bugs.php.net/bug.php?id=74912&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74912&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74912&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74912&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74912&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74912&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74912&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74912&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74912&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74912&r=support Expected behavior: https://bugs.php.net/fix.php?id=74912&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74912&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74912&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74912&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74912&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74912&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74912&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74912&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74912&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74912&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74912&r=mysqlcfg

« previous php.bugs (#210022) next »