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