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