xref: /PHP-8.3/ext/pgsql/tests/12pg_insert_9.phpt (revision e378968c)
1--TEST--
2PostgreSQL pg_insert() (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
21pg_insert($db, $table_name, $fields) or print "Error in test 1\n";
22echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n";
23echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";
24var_dump( pg_insert($db, $table_name, $fields, PGSQL_DML_EXEC) );
25
26/* Invalid values */
27try {
28    $converted = pg_insert($db, $table_name, [5 => 'AAA']);
29} catch (\ValueError $e) {
30    echo $e->getMessage(), \PHP_EOL;
31}
32try {
33    $converted = pg_insert($db, $table_name, ['AAA']);
34} catch (\ValueError $e) {
35    echo $e->getMessage(), \PHP_EOL;
36}
37try {
38    $converted = pg_insert($db, $table_name, ['num' => []]);
39} catch (\TypeError $e) {
40    echo $e->getMessage(), \PHP_EOL;
41}
42try {
43    $converted = pg_insert($db, $table_name, ['num' => new stdClass()]);
44} catch (\TypeError $e) {
45    echo $e->getMessage(), \PHP_EOL;
46}
47try {
48    $converted = pg_insert($db, $table_name, ['num' => $db]);
49    var_dump($converted);
50} catch (\TypeError $e) {
51    echo $e->getMessage(), \PHP_EOL;
52}
53
54echo "Ok\n";
55?>
56--EXPECTF--
57INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
58INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES ('1234','AAA','BBB');
59object(PgSql\Result)#%d (0) {
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
66Ok
67