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