xref: /PHP-8.3/ext/pdo_mysql/tests/bug_45120.phpt (revision 39131219)
1--TEST--
2Bug #45120 (PDOStatement->execute() returns true then false for same statement)
3--EXTENSIONS--
4pdo
5pdo_mysql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14require __DIR__ . '/config.inc';
15require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
16$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
17
18function bug_45120($db) {
19
20    $stmt = $db->prepare("SELECT 1 AS 'one'");
21    if (true !== $stmt->execute())
22        printf("[001] Execute has failed: %s\n", var_export($stmt->errorInfo(), true));
23
24    $res = $stmt->fetch(PDO::FETCH_ASSOC);
25    if ($res['one'] != 1)
26        printf("[002] Wrong results: %s\n", var_export($res, true));
27
28    if (true !== $stmt->execute())
29        printf("[003] Execute has failed: %s\n", var_export($stmt->errorInfo(), true));
30
31    $res = $stmt->fetch(PDO::FETCH_ASSOC);
32    if ($res['one'] != 1)
33        printf("[004] Wrong results: %s\n", var_export($res, true));
34
35}
36
37print "Emulated Prepared Statements\n";
38$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
39bug_45120($db);
40
41print "Native Prepared Statements\n";
42$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
43bug_45120($db);
44
45print "done!";
46?>
47--EXPECT--
48Emulated Prepared Statements
49Native Prepared Statements
50done!
51