24sync_query_prepared.phpt 1.4 KB

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