1--TEST--
2PostgreSQL async query params
3--EXTENSIONS--
4pgsql
5--SKIPIF--
6<?php
7include("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('config.inc');
14
15$db = pg_connect($conn_str);
16
17$version = pg_version($db);
18if ($version['protocol'] >= 3) {
19    if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
20        echo "pg_send_query_params() error\n";
21    }
22    while(pg_connection_busy($db));  // busy wait: intended
23    if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
24        echo "pg_connection_status() error\n";
25    }
26    if (!($result = pg_get_result($db)))
27    {
28        echo "pg_get_result() error\n";
29    }
30    if (!($rows = pg_num_rows($result))) {
31        echo "pg_num_rows() error\n";
32    }
33    for ($i=0; $i < $rows; $i++)
34    {
35        pg_fetch_array($result, $i, PGSQL_NUM);
36    }
37    for ($i=0; $i < $rows; $i++)
38    {
39        pg_fetch_object($result);
40    }
41    for ($i=0; $i < $rows; $i++)
42    {
43        pg_fetch_row($result, $i);
44    }
45    for ($i=0; $i < $rows; $i++)
46    {
47        pg_fetch_result($result, $i, 0);
48    }
49
50    pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
51    pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
52    pg_field_name($result, 0);
53    pg_field_num($result, $field_name);
54    pg_field_size($result, 0);
55    pg_field_type($result, 0);
56    pg_field_prtlen($result, 0);
57    pg_field_is_null($result, 0);
58
59    if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
60    {
61        echo "pg_send_query_params() error\n";
62    }
63
64    pg_last_oid($result);
65    pg_free_result($result);
66}
67pg_close($db);
68
69echo "OK";
70?>
71--EXPECT--
72OK
73