1--TEST-- 2PostgreSQL pg_convert() (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_10pg_convert_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$converted = pg_convert($db, $table_name, $fields); 24 25var_dump($converted); 26 27/* Invalid values */ 28try { 29 $converted = pg_convert($db, $table_name, [5 => 'AAA']); 30} catch (\ValueError $e) { 31 echo $e->getMessage(), \PHP_EOL; 32} 33try { 34 $converted = pg_convert($db, $table_name, ['AAA']); 35} catch (\ValueError $e) { 36 echo $e->getMessage(), \PHP_EOL; 37} 38try { 39 $converted = pg_convert($db, $table_name, ['num' => []]); 40} catch (\TypeError $e) { 41 echo $e->getMessage(), \PHP_EOL; 42} 43try { 44 $converted = pg_convert($db, $table_name, ['num' => new stdClass()]); 45} catch (\TypeError $e) { 46 echo $e->getMessage(), \PHP_EOL; 47} 48try { 49 $converted = pg_convert($db, $table_name, ['num' => $db]); 50 var_dump($converted); 51} catch (\TypeError $e) { 52 echo $e->getMessage(), \PHP_EOL; 53} 54?> 55--CLEAN-- 56<?php 57include('inc/config.inc'); 58$table_name = "table_10pg_convert_9"; 59 60$db = pg_connect($conn_str); 61pg_query($db, "DROP TABLE IF EXISTS {$table_name}"); 62?> 63--EXPECT-- 64array(3) { 65 [""num""]=> 66 string(4) "1234" 67 [""str""]=> 68 string(6) "E'AAA'" 69 [""bin""]=> 70 string(12) "E'\\x424242'" 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 77