1--TEST--
2PostgreSQL async query params
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("inc/skipif.inc");
8if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_params() does not exist');
9?>
10--FILE--
11<?php
12
13include('inc/config.inc');
14$table_name = "table_25async_query_params";
15
16$db = pg_connect($conn_str);
17pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
18pg_query($db, "INSERT INTO {$table_name} (num) VALUES(1000)");
19
20if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
21	echo "pg_send_query_params() error\n";
22}
23while(pg_connection_busy($db));  // busy wait: intended
24if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
25	echo "pg_connection_status() error\n";
26}
27if (!($result = pg_get_result($db)))
28{
29	echo "pg_get_result() error\n";
30}
31if (!($rows = pg_num_rows($result))) {
32	echo "pg_num_rows() error\n";
33}
34for ($i=0; $i < $rows; $i++)
35{
36	pg_fetch_array($result, $i, PGSQL_NUM);
37}
38for ($i=0; $i < $rows; $i++)
39{
40	pg_fetch_object($result);
41}
42for ($i=0; $i < $rows; $i++)
43{
44	pg_fetch_row($result, $i);
45}
46for ($i=0; $i < $rows; $i++)
47{
48	pg_fetch_result($result, $i, 0);
49}
50
51pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
52pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
53pg_field_name($result, 0);
54pg_field_num($result, "num");
55pg_field_size($result, 0);
56pg_field_type($result, 0);
57pg_field_prtlen($result, null, 0);
58pg_field_is_null($result, null, 0);
59
60if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
61{
62	echo "pg_send_query_params() error\n";
63}
64
65pg_last_oid($result);
66pg_free_result($result);
67pg_close($db);
68
69echo "OK";
70?>
71--CLEAN--
72<?php
73include('inc/config.inc');
74$table_name = "table_25async_query_params";
75
76$db = pg_connect($conn_str);
77pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
78?>
79--EXPECT--
80OK
81