1--TEST-- 2PDO PgSQL Bug #62593 (Emulate prepares behave strangely with PARAM_BOOL) 3--EXTENSIONS-- 4pdo_pgsql 5--SKIPIF-- 6<?php 7require __DIR__ . '/config.inc'; 8require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 9PDOTest::skip(); 10?> 11--FILE-- 12<?php 13require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; 14$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); 15$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); 16$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); 17$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); 18$errors = array(); 19 20$value = true; 21$query = $db->prepare('SELECT :foo IS FALSE as val_is_false'); 22$query->bindValue(':foo', $value, PDO::PARAM_BOOL); 23$query->execute(); 24$errors[] = $query->errorInfo(); 25var_dump($value); 26 27$query->bindValue(':foo', 0, PDO::PARAM_BOOL); 28$query->execute(); 29$errors[] = $query->errorInfo(); 30 31// Verify bindParam maintains reference and only passes when execute is called 32$value = true; 33$query->bindParam(':foo', $value, PDO::PARAM_BOOL); 34$value = false; 35$query->execute(); 36$errors[] = $query->errorInfo(); 37var_dump($value); 38 39// Try with strings - Bug #68351 40$value = '0'; 41$query->bindParam(':foo', $value, PDO::PARAM_BOOL); 42$query->execute(); 43$errors[] = $query->errorInfo(); 44var_dump($query->fetchColumn()); 45 46$value = "abc"; 47$query->bindParam(':foo', $value, PDO::PARAM_BOOL); 48$query->execute(); 49$errors[] = $query->errorInfo(); 50var_dump($query->fetchColumn()); 51 52$expect = 'No errors found'; 53 54foreach ($errors as $error) 55{ 56 if (null !== $error[2] && strpos('Invalid text representation', $error[2]) !== false) 57 { 58 $expect = 'Invalid boolean found'; 59 } 60} 61echo $expect; 62?> 63--EXPECT-- 64bool(true) 65bool(false) 66bool(true) 67bool(false) 68No errors found 69