xref: /PHP-7.0/ext/pdo/tests/bug_65946.phpt (revision 69013f6b)
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 'firebird':
26		$sql = 'SELECT FIRST :limit * FROM test';
27		break;
28	case 'oci':
29		//$sql = 'SELECT * FROM test FETCH FIRST :limit ROWS ONLY';  // Oracle 12c syntax
30		$sql = "select id from (select a.*, rownum rnum from (SELECT * FROM test) a where rownum <= :limit)";
31		break;
32	default:
33		$sql = 'SELECT * FROM test LIMIT :limit';
34		break;
35}
36$stmt = $db->prepare($sql);
37$stmt->bindValue('limit', 1, PDO::PARAM_INT);
38if(!($res = $stmt->execute())) var_dump($stmt->errorInfo());
39if(!($res = $stmt->execute())) var_dump($stmt->errorInfo());
40var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
41?>
42--EXPECTF--
43array(1) {
44  [0]=>
45  array(1) {
46    ["id"]=>
47    string(1) "1"
48  }
49}
50