24sync_query_prepared.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --TEST--
  2. PostgreSQL sync prepared queries
  3. --EXTENSIONS--
  4. pgsql
  5. --SKIPIF--
  6. <?php
  7. include("skipif.inc");
  8. if (!function_exists('pg_prepare')) die('skip function pg_prepare() does not exist');
  9. ?>
  10. --FILE--
  11. <?php
  12. include('config.inc');
  13. $db = pg_connect($conn_str);
  14. $version = pg_version($db);
  15. if ($version['protocol'] >= 3) {
  16. $result = pg_prepare($db, "php_test", "SELECT * FROM ".$table_name." WHERE num > \$1;");
  17. pg_result_error($result);
  18. pg_free_result($result);
  19. $result = pg_execute($db, "php_test", array(100));
  20. if (!($rows = pg_num_rows($result)))
  21. {
  22. echo "pg_num_row() error\n";
  23. }
  24. for ($i=0; $i < $rows; $i++)
  25. {
  26. pg_fetch_array($result, $i, PGSQL_NUM);
  27. }
  28. for ($i=0; $i < $rows; $i++)
  29. {
  30. pg_fetch_object($result);
  31. }
  32. for ($i=0; $i < $rows; $i++)
  33. {
  34. pg_fetch_row($result, $i);
  35. }
  36. for ($i=0; $i < $rows; $i++)
  37. {
  38. pg_fetch_result($result, $i, 0);
  39. }
  40. pg_result_error($result);
  41. pg_num_rows(pg_execute($db, "php_test", array(100)));
  42. pg_num_fields(pg_execute($db, "php_test", array(100)));
  43. pg_field_name($result, 0);
  44. pg_field_num($result, $field_name);
  45. pg_field_size($result, 0);
  46. pg_field_type($result, 0);
  47. pg_field_prtlen($result, 0);
  48. pg_field_is_null($result, 0);
  49. $result = pg_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
  50. pg_result_error($result);
  51. pg_free_result($result);
  52. $result = pg_execute($db, "php_test2", array(9999, "A'BC"));
  53. pg_last_oid($result);
  54. pg_free_result($result);
  55. }
  56. pg_close($db);
  57. echo "OK";
  58. ?>
  59. --EXPECT--
  60. OK