1--TEST-- 2PostgreSQL pg_insert() (9.0+) 3--EXTENSIONS-- 4pgsql 5--SKIPIF-- 6<?php 7include("inc/skipif.inc"); 8skip_bytea_not_hex(); 9?> 10--FILE-- 11<?php 12error_reporting(E_ALL); 13 14include 'inc/config.inc'; 15$table_name = "table_12pg_insert_9"; 16 17$db = pg_connect($conn_str); 18pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)"); 19 20pg_query($db, "SET standard_conforming_strings = 0"); 21 22$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB'); 23 24pg_insert($db, $table_name, $fields) or print "Error in test 1\n"; 25echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n"; 26echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n"; 27var_dump( pg_insert($db, $table_name, $fields, PGSQL_DML_EXEC) ); 28 29/* Invalid values */ 30try { 31 $converted = pg_insert($db, $table_name, [5 => 'AAA']); 32} catch (\ValueError $e) { 33 echo $e->getMessage(), \PHP_EOL; 34} 35try { 36 $converted = pg_insert($db, $table_name, ['AAA']); 37} catch (\ValueError $e) { 38 echo $e->getMessage(), \PHP_EOL; 39} 40try { 41 $converted = pg_insert($db, $table_name, ['num' => []]); 42} catch (\TypeError $e) { 43 echo $e->getMessage(), \PHP_EOL; 44} 45try { 46 $converted = pg_insert($db, $table_name, ['num' => new stdClass()]); 47} catch (\TypeError $e) { 48 echo $e->getMessage(), \PHP_EOL; 49} 50try { 51 $converted = pg_insert($db, $table_name, ['num' => $db]); 52 var_dump($converted); 53} catch (\TypeError $e) { 54 echo $e->getMessage(), \PHP_EOL; 55} 56 57echo "Ok\n"; 58?> 59--CLEAN-- 60<?php 61include('inc/config.inc'); 62$table_name = "table_12pg_insert_9"; 63 64$db = pg_connect($conn_str); 65pg_query($db, "DROP TABLE IF EXISTS {$table_name}"); 66?> 67--EXPECTF-- 68INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242'); 69INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES ('1234','AAA','BBB'); 70object(PgSql\Result)#%d (0) { 71} 72Array of values must be an associative array with string keys 73Array of values must be an associative array with string keys 74Values must be of type string|int|float|bool|null, array given 75Values must be of type string|int|float|bool|null, stdClass given 76Values must be of type string|int|float|bool|null, PgSql\Connection given 77Ok 78