1--TEST-- 2PostgreSQL non-blocking async queries 3--EXTENSIONS-- 4pgsql 5--SKIPIF-- 6<?php 7include("inc/skipif.inc"); 8if (!function_exists('pg_send_prepare')) die('skip function pg_send_prepare() does not exist'); 9?> 10--FILE-- 11<?php 12 13include('inc/config.inc'); 14include('inc/nonblocking.inc'); 15$table_name = "table_32nb_async_query"; 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} DEFAULT VALUES"); 20 21$db_socket = pg_socket($db); 22stream_set_blocking($db_socket, false); 23 24$nb_send = pg_send_query($db, "SELECT * FROM ".$table_name.";"); 25if ($nb_send === FALSE) { 26 echo "pg_send_query() error\n"; 27} elseif ($nb_send === 0) { 28 nb_flush($db, $db_socket); 29} 30 31nb_consume($db, $db_socket); 32 33if (!($result = pg_get_result($db))) { 34 echo "pg_get_result() error\n"; 35} 36 37if (!($rows = pg_num_rows($result))) { 38 echo "pg_num_rows() error\n"; 39} 40for ($i=0; $i < $rows; $i++) { 41 pg_fetch_array($result, $i, PGSQL_NUM); 42} 43for ($i=0; $i < $rows; $i++) { 44 pg_fetch_object($result); 45} 46for ($i=0; $i < $rows; $i++) { 47 pg_fetch_row($result, $i); 48} 49for ($i=0; $i < $rows; $i++) { 50 pg_fetch_result($result, $i, 0); 51} 52 53pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";")); 54pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";")); 55pg_field_name($result, 0); 56pg_field_num($result, "num"); 57pg_field_size($result, 0); 58pg_field_type($result, 0); 59pg_field_prtlen($result, null, 0); 60pg_field_is_null($result, null, 0); 61 62$nb_send = pg_send_query($db, "INSERT INTO ".$table_name." VALUES (8888, 'GGG');"); 63if ($nb_send === FALSE) { 64 echo "pg_send_query() error\n"; 65} elseif ($nb_send === 0) { 66 nb_flush($db, $db_socket); 67} 68 69nb_consume($db, $db_socket); 70 71if (!($result = pg_get_result($db))) { 72 echo "pg_get_result() error\n"; 73} 74 75pg_last_oid($result); 76pg_free_result($result); 77pg_close($db); 78 79echo "OK"; 80?> 81--CLEAN-- 82<?php 83include('inc/config.inc'); 84$table_name = "table_32nb_async_query"; 85 86$db = pg_connect($conn_str); 87pg_query($db, "DROP TABLE IF EXISTS {$table_name}"); 88?> 89--EXPECT-- 90OK 91