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