xref: /PHP-8.0/ext/pdo/tests/gh8626.phpt (revision 30589258)
1--TEST--
2GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8require_once $dir . 'pdo_test.inc';
9PDOTest::skip();
10
11$db = PDOTest::factory();
12if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
13    die("xfail OCI driver errorInfo is inconsistent with other PDO drivers");
14}
15?>
16--FILE--
17<?php
18if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
19require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
20
21$db = PDOTest::factory();
22$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
23
24$db->exec('DROP TABLE test');
25$db->exec('CREATE TABLE test (x int NOT NULL)');
26
27$stmt = $db->prepare('INSERT INTO test VALUES(?)');
28
29// fail
30var_dump($stmt->execute([null]), $stmt->errorCode());
31$errorInfo = $stmt->errorInfo();
32var_dump(array_slice($errorInfo, 0, 3)); // odbc, dblib
33
34$stmt->closeCursor(); // sqlite
35
36// success
37var_dump($stmt->execute([1]), $stmt->errorCode());
38$errorInfo = $stmt->errorInfo();
39var_dump(array_slice($errorInfo, 0, 3)); // odbc, dblib
40?>
41===DONE===
42--EXPECTF--
43bool(false)
44string(%d) "%s"
45array(3) {
46  [0]=>
47  string(%d) "%s"
48  [1]=>
49  int(%d)
50  [2]=>
51  string(%d) "%s%w%S"
52}
53bool(true)
54string(5) "00000"
55array(3) {
56  [0]=>
57  string(5) "00000"
58  [1]=>
59  NULL
60  [2]=>
61  NULL
62}
63===DONE===
64