xref: /PHP-8.3/ext/pgsql/tests/13pg_select_9.phpt (revision 1f427779)
1--TEST--
2PostgreSQL pg_select() (9.0+)
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("skipif.inc");
8skip_server_version('9.0', '<');
9?>
10--FILE--
11<?php
12error_reporting(E_ALL);
13
14include 'config.inc';
15
16$db = pg_connect($conn_str);
17pg_query($db, "SET bytea_output = 'hex'");
18
19$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
20$ids = array('num'=>'1234');
21
22$res = pg_select($db, $table_name, $ids) or print "Error\n";
23var_dump($res);
24echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n";
25echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";
26
27/* Invalid values */
28try {
29    $converted = pg_select($db, $table_name, [5 => 'AAA']);
30} catch (\ValueError $e) {
31    echo $e->getMessage(), \PHP_EOL;
32}
33try {
34    $converted = pg_select($db, $table_name, ['AAA']);
35} catch (\ValueError $e) {
36    echo $e->getMessage(), \PHP_EOL;
37}
38try {
39    $converted = pg_select($db, $table_name, ['num' => []]);
40} catch (\TypeError $e) {
41    echo $e->getMessage(), \PHP_EOL;
42}
43try {
44    $converted = pg_select($db, $table_name, ['num' => new stdClass()]);
45} catch (\TypeError $e) {
46    echo $e->getMessage(), \PHP_EOL;
47}
48try {
49    $converted = pg_select($db, $table_name, ['num' => $db]);
50    var_dump($converted);
51} catch (\TypeError $e) {
52    echo $e->getMessage(), \PHP_EOL;
53}
54
55echo "Ok\n";
56
57?>
58--EXPECT--
59array(2) {
60  [0]=>
61  array(3) {
62    ["num"]=>
63    string(4) "1234"
64    ["str"]=>
65    string(3) "AAA"
66    ["bin"]=>
67    string(8) "\x424242"
68  }
69  [1]=>
70  array(3) {
71    ["num"]=>
72    string(4) "1234"
73    ["str"]=>
74    string(3) "AAA"
75    ["bin"]=>
76    string(8) "\x424242"
77  }
78}
79SELECT * FROM "php_pgsql_test" WHERE "num"=1234;
80SELECT * FROM "php_pgsql_test" WHERE "num"='1234';
81Array of values must be an associative array with string keys
82Array of values must be an associative array with string keys
83Values must be of type string|int|float|bool|null, array given
84Values must be of type string|int|float|bool|null, stdClass given
85Values must be of type string|int|float|bool|null, PgSql\Connection given
86Ok
87