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