xref: /PHP-8.3/ext/pdo_pgsql/tests/bug71885_2.phpt (revision 39131219)
1--TEST--
2Request #71855 (PDO placeholder escaping, part 2)
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
9require_once dirname(__FILE__) . '/config.inc';
10PDOTest::skip();
11
12$db = PDOTest::factory();
13if (version_compare($db->getAttribute(PDO::ATTR_SERVER_VERSION), '9.4.0') < 0) {
14        die("skip Requires 9.4+");
15}
16
17?>
18--FILE--
19<?php
20require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
21require_once dirname(__FILE__) . '/config.inc';
22$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
23$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
24$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NUM);
25
26$jsonb = $db->quote(json_encode(['a' => 1]));
27
28foreach ([false, true] as $emulate) {
29    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulate);
30
31    $stmt = $db->prepare("SELECT {$jsonb}::jsonb ?? ?");
32    $stmt->execute(['b']);
33    var_dump($stmt->fetch());
34
35    $stmt = $db->prepare("SELECT {$jsonb}::jsonb ???");
36    $stmt->execute(['a']);
37    var_dump($stmt->fetch());
38}
39
40?>
41==OK==
42--EXPECT--
43array(1) {
44  [0]=>
45  string(1) "0"
46}
47array(1) {
48  [0]=>
49  string(1) "1"
50}
51array(1) {
52  [0]=>
53  string(1) "0"
54}
55array(1) {
56  [0]=>
57  string(1) "1"
58}
59==OK==
60