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