xref: /PHP-8.0/ext/pgsql/tests/12pg_insert_9.phpt (revision 053a5fc1)
1--TEST--
2PostgreSQL pg_insert() (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
19pg_insert($db, $table_name, $fields) or print "Error in test 1\n";
20echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n";
21echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";
22var_dump( pg_insert($db, $table_name, $fields, PGSQL_DML_EXEC) ); // Return resource
23
24/* Invalid values */
25try {
26    $converted = pg_insert($db, $table_name, [5 => 'AAA']);
27} catch (\ValueError $e) {
28    echo $e->getMessage(), \PHP_EOL;
29}
30try {
31    $converted = pg_insert($db, $table_name, ['AAA']);
32} catch (\ValueError $e) {
33    echo $e->getMessage(), \PHP_EOL;
34}
35try {
36    $converted = pg_insert($db, $table_name, ['num' => []]);
37} catch (\TypeError $e) {
38    echo $e->getMessage(), \PHP_EOL;
39}
40try {
41    $converted = pg_insert($db, $table_name, ['num' => new stdClass()]);
42} catch (\TypeError $e) {
43    echo $e->getMessage(), \PHP_EOL;
44}
45try {
46    $converted = pg_insert($db, $table_name, ['num' => $db]);
47    var_dump($converted);
48} catch (\TypeError $e) {
49    echo $e->getMessage(), \PHP_EOL;
50}
51
52echo "Ok\n";
53?>
54--EXPECTF--
55INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
56INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES ('1234','AAA','BBB');
57resource(%d) of type (pgsql result)
58Array of values must be an associative array with string keys
59Array of values must be an associative array with string keys
60Values must be of type string|int|float|bool|null, array given
61Values must be of type string|int|float|bool|null, stdClass given
62Values must be of type string|int|float|bool|null, resource given
63Ok
64