xref: /PHP-7.4/ext/pdo/tests/bug_71885.phpt (revision b19fdc18)
1--TEST--
2PDO Common: FR #71885 (Allow escaping question mark placeholders)
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8if (!strncasecmp(getenv('PDOTEST_DSN'), 'pgsql', strlen('pgsql'))) die('skip not relevant for pgsql driver');
9if (!strncasecmp(getenv('PDOTEST_DSN'), 'odbc', strlen('odbc'))) die('skip inconsistent error message with odbc');
10require_once $dir . 'pdo_test.inc';
11PDOTest::skip();
12?>
13--FILE--
14<?php
15if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
16require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
17$db = PDOTest::factory();
18$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
19
20$db->exec("CREATE TABLE test (a int)");
21
22$sql = "SELECT * FROM test WHERE a ?? 1";
23
24try {
25	$db->exec($sql);
26} catch (PDOException $e) {
27	var_dump(strpos($e->getMessage(), "?") !== false);
28}
29
30try {
31	$stmt = $db->prepare($sql);
32	$stmt->execute();
33} catch (PDOException $e) {
34	var_dump(strpos($e->getMessage(), "?") !== false);
35}
36
37if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
38	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
39}
40
41try {
42	$stmt = $db->prepare($sql);
43	$stmt->execute();
44} catch (PDOException $e) {
45	var_dump(strpos($e->getMessage(), "?") !== false);
46}
47
48?>
49===DONE===
50--EXPECT--
51bool(true)
52bool(true)
53bool(true)
54===DONE===
55