|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-07-12 16:02 UTC] marc dot w dot hagen at gmail dot com
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'"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
INSERT INTO someTable(...) VALUES(...),(...),.. ON DUPLICATE KEY UPDATE field1 = VALUES(field1), field2 = VALUES(field2) CREATE TABLE someTable ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, subId VARCHAR(255) NOT NULL, ... PRIMARY KEY (id), UNIQUE KEY k_transaction(subId),