xref: /PHP-8.3/ext/pdo/tests/bug_65946.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #65946 (pdo_sql_parser.c permanently converts values bound to strings)
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--FILE--
13<?php
14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
16$db = PDOTest::factory();
17$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
18$db->exec('CREATE TABLE test(id int)');
19$db->exec('INSERT INTO test VALUES(1)');
20switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
21    case 'dblib':
22        $sql = 'SELECT TOP :limit * FROM test';
23        break;
24    case 'odbc':
25        $sql = 'SELECT TOP (:limit) * FROM test';
26        break;
27    case 'firebird':
28        $sql = 'SELECT FIRST :limit * FROM test';
29        break;
30    case 'oci':
31        //$sql = 'SELECT * FROM test FETCH FIRST :limit ROWS ONLY';  // Oracle 12c syntax
32        $sql = "select id from (select a.*, rownum rnum from (SELECT * FROM test) a where rownum <= :limit)";
33        break;
34    default:
35        $sql = 'SELECT * FROM test LIMIT :limit';
36        break;
37}
38$stmt = $db->prepare($sql);
39$stmt->bindValue('limit', 1, PDO::PARAM_INT);
40if(!($res = $stmt->execute())) var_dump($stmt->errorInfo());
41if(!($res = $stmt->execute())) var_dump($stmt->errorInfo());
42var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
43?>
44--EXPECT--
45array(1) {
46  [0]=>
47  array(1) {
48    ["id"]=>
49    string(1) "1"
50  }
51}
52