xref: /PHP-8.1/ext/pdo_pgsql/tests/bug64953.phpt (revision 39131219)
1--TEST--
2PDO PgSQL Bug #64953 (Postgres prepared statement positional parameter casting)
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
14echo "Test\n";
15
16require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
17$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
18$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
19
20echo "Taken from the bug report:\n";
21
22$st = $pdo->prepare('SELECT ?::char as i');
23$st->bindValue(1, '1');
24$st->execute();
25var_dump($st->fetch()); // return false
26
27
28$st = $pdo->prepare('SELECT (?)::char as i');
29$st->bindValue(1, '1');
30$st->execute();
31var_dump($st->fetch());  // return array(1) { ["i"]=> string(1) "1" }
32
33echo "Something more nasty:\n";
34
35$st = $pdo->prepare("SELECT :int::int as i");
36$st->execute(array(":int" => 123));
37var_dump($st->fetch());
38
39$st = $pdo->prepare("SELECT '''?'''::text as \":text\"");
40$st->execute();
41var_dump($st->fetch());
42
43?>
44Done
45--EXPECT--
46Test
47Taken from the bug report:
48array(2) {
49  ["i"]=>
50  string(1) "1"
51  [0]=>
52  string(1) "1"
53}
54array(2) {
55  ["i"]=>
56  string(1) "1"
57  [0]=>
58  string(1) "1"
59}
60Something more nasty:
61array(2) {
62  ["i"]=>
63  string(3) "123"
64  [0]=>
65  string(3) "123"
66}
67array(2) {
68  [":text"]=>
69  string(3) "'?'"
70  [0]=>
71  string(3) "'?'"
72}
73Done
74