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