1--TEST--
2PostgreSQL non-blocking 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');
14include('nonblocking.inc');
15
16$db = pg_connect($conn_str);
17
18$version = pg_version($db);
19if ($version['protocol'] < 3) {
20    echo "OK";
21    exit(0);
22}
23
24$db_socket = pg_socket($db);
25stream_set_blocking($db_socket, false);
26
27$sent = pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
28if ($sent === FALSE) {
29    echo "pg_send_query_params() error\n";
30} elseif ($sent === 0) {
31    nb_flush($db, $db_socket);
32}
33
34nb_consume($db, $db_socket);
35
36if (!($result = pg_get_result($db))) {
37    echo "pg_get_result() error\n";
38}
39if (!($rows = pg_num_rows($result))) {
40    echo "pg_num_rows() error\n";
41}
42for ($i=0; $i < $rows; $i++) {
43    pg_fetch_array($result, $i, PGSQL_NUM);
44}
45for ($i=0; $i < $rows; $i++) {
46    pg_fetch_object($result);
47}
48for ($i=0; $i < $rows; $i++) {
49    pg_fetch_row($result, $i);
50}
51for ($i=0; $i < $rows; $i++) {
52    pg_fetch_result($result, $i, 0);
53}
54
55pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
56pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
57pg_field_name($result, 0);
58pg_field_num($result, $field_name);
59pg_field_size($result, 0);
60pg_field_type($result, 0);
61pg_field_prtlen($result, 0);
62pg_field_is_null($result, 0);
63
64$sent = pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
65
66if ($sent === FALSE) {
67    echo "pg_send_query_params() error\n";
68} elseif ($sent === 0) {
69    nb_flush($db, $db_socket);
70}
71
72pg_last_oid($result);
73pg_free_result($result);
74
75pg_close($db);
76
77echo "OK";
78?>
79--EXPECT--
80OK
81