1--TEST-- 2PostgreSQL pg_select() (9.0+) 3--EXTENSIONS-- 4pgsql 5--SKIPIF-- 6<?php 7include("inc/skipif.inc"); 8skip_server_version('9.0', '<'); 9?> 10--FILE-- 11<?php 12error_reporting(E_ALL); 13 14include 'inc/config.inc'; 15$table_name = "table_13pg_select_9"; 16 17$db = pg_connect($conn_str); 18pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)"); 19pg_query($db, "INSERT INTO {$table_name} VALUES(1234, 'AAA', 'BBB')"); 20pg_query($db, "INSERT INTO {$table_name} VALUES(1234, 'AAA', 'BBB')"); 21 22pg_query($db, "SET bytea_output = 'hex'"); 23 24$ids = array('num'=>'1234'); 25 26$res = pg_select($db, $table_name, $ids) or print "Error\n"; 27var_dump($res); 28echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n"; 29echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n"; 30 31/* Invalid values */ 32try { 33 $converted = pg_select($db, $table_name, [5 => 'AAA']); 34} catch (\ValueError $e) { 35 echo $e->getMessage(), \PHP_EOL; 36} 37try { 38 $converted = pg_select($db, $table_name, ['AAA']); 39} catch (\ValueError $e) { 40 echo $e->getMessage(), \PHP_EOL; 41} 42try { 43 $converted = pg_select($db, $table_name, ['num' => []]); 44} catch (\TypeError $e) { 45 echo $e->getMessage(), \PHP_EOL; 46} 47try { 48 $converted = pg_select($db, $table_name, ['num' => new stdClass()]); 49} catch (\TypeError $e) { 50 echo $e->getMessage(), \PHP_EOL; 51} 52try { 53 $converted = pg_select($db, $table_name, ['num' => $db]); 54 var_dump($converted); 55} catch (\TypeError $e) { 56 echo $e->getMessage(), \PHP_EOL; 57} 58 59echo "Ok\n"; 60 61?> 62--CLEAN-- 63<?php 64include('inc/config.inc'); 65$table_name = "table_13pg_select_9"; 66 67$db = pg_connect($conn_str); 68pg_query($db, "DROP TABLE IF EXISTS {$table_name}"); 69?> 70--EXPECT-- 71array(2) { 72 [0]=> 73 array(3) { 74 ["num"]=> 75 string(4) "1234" 76 ["str"]=> 77 string(3) "AAA" 78 ["bin"]=> 79 string(8) "\x424242" 80 } 81 [1]=> 82 array(3) { 83 ["num"]=> 84 string(4) "1234" 85 ["str"]=> 86 string(3) "AAA" 87 ["bin"]=> 88 string(8) "\x424242" 89 } 90} 91SELECT * FROM "table_13pg_select_9" WHERE "num"=1234; 92SELECT * FROM "table_13pg_select_9" WHERE "num"='1234'; 93Array of values must be an associative array with string keys 94Array of values must be an associative array with string keys 95Values must be of type string|int|float|bool|null, array given 96Values must be of type string|int|float|bool|null, stdClass given 97Values must be of type string|int|float|bool|null, PgSql\Connection given 98Ok 99