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