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