xref: /PHP-5.3/ext/pdo_pgsql/tests/bug62593.phpt (revision d922e801)
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$expect = 'No errors found';
38
39foreach ($errors as $error)
40{
41  if (strpos('Invalid text representation', $error[2]) !== false)
42  {
43    $expect = 'Invalid boolean found';
44  }
45}
46echo $expect;
47?>
48--EXPECTF--
49bool(true)
50bool(false)
51No errors found
52