xref: /php-src/ext/pdo_mysql/tests/bug79132.phpt (revision 4bb75d56)
1--TEST--
2Bug #79132: PDO re-uses parameter values from earlier calls to execute()
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13
14$pdo = MySQLPDOTest::factory();
15$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
16
17$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
18test($pdo);
19echo "\n";
20$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
21test($pdo);
22
23function test($pdo) {
24    $stmt = $pdo->prepare('SELECT ? a, ? b');
25
26    $set = [
27        ['a', 'b'],
28        ['x'],      /* second parameter is missing */
29        [1 => 'y'], /* first parameter is missing */
30    ];
31
32    foreach ($set as $params) {
33        try {
34            var_dump($stmt->execute($params), $stmt->fetchAll(PDO::FETCH_ASSOC));
35        } catch (PDOException $error) {
36            echo $error->getMessage() . "\n";
37        }
38    }
39}
40
41?>
42--EXPECT--
43bool(true)
44array(1) {
45  [0]=>
46  array(2) {
47    ["a"]=>
48    string(1) "a"
49    ["b"]=>
50    string(1) "b"
51  }
52}
53SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
54SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
55
56bool(true)
57array(1) {
58  [0]=>
59  array(2) {
60    ["a"]=>
61    string(1) "a"
62    ["b"]=>
63    string(1) "b"
64  }
65}
66SQLSTATE[HY093]: Invalid parameter number
67SQLSTATE[HY093]: Invalid parameter number
68