xref: /PHP-8.0/ext/pgsql/tests/10pg_convert_9.phpt (revision 053a5fc1)
1--TEST--
2PostgreSQL pg_convert() (9.0+)
3--SKIPIF--
4<?php
5include("skipif.inc");
6skip_bytea_not_hex();
7?>
8--FILE--
9<?php
10error_reporting(E_ALL);
11
12include 'config.inc';
13
14$db = pg_connect($conn_str);
15pg_query($db, "SET standard_conforming_strings = 0");
16
17$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
18$converted = pg_convert($db, $table_name, $fields);
19
20var_dump($converted);
21
22/* Invalid values */
23try {
24    $converted = pg_convert($db, $table_name, [5 => 'AAA']);
25} catch (\ValueError $e) {
26    echo $e->getMessage(), \PHP_EOL;
27}
28try {
29    $converted = pg_convert($db, $table_name, ['AAA']);
30} catch (\ValueError $e) {
31    echo $e->getMessage(), \PHP_EOL;
32}
33try {
34    $converted = pg_convert($db, $table_name, ['num' => []]);
35} catch (\TypeError $e) {
36    echo $e->getMessage(), \PHP_EOL;
37}
38try {
39    $converted = pg_convert($db, $table_name, ['num' => new stdClass()]);
40} catch (\TypeError $e) {
41    echo $e->getMessage(), \PHP_EOL;
42}
43try {
44    $converted = pg_convert($db, $table_name, ['num' => $db]);
45    var_dump($converted);
46} catch (\TypeError $e) {
47    echo $e->getMessage(), \PHP_EOL;
48}
49?>
50--EXPECT--
51array(3) {
52  [""num""]=>
53  string(4) "1234"
54  [""str""]=>
55  string(6) "E'AAA'"
56  [""bin""]=>
57  string(12) "E'\\x424242'"
58}
59Array of values must be an associative array with string keys
60Array of values must be an associative array with string keys
61Values must be of type string|int|float|bool|null, array given
62Values must be of type string|int|float|bool|null, stdClass given
63Values must be of type string|int|float|bool|null, resource given
64