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