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