26async_query_prepared.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. --TEST--
  2. PostgreSQL async prepared queries
  3. --SKIPIF--
  4. <?php
  5. include("skipif.inc");
  6. if (!function_exists('pg_send_prepare')) die('skip function pg_send_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. if (!pg_send_prepare($db, 'php_test', "SELECT * FROM ".$table_name." WHERE num > \$1;")) {
  15. echo "pg_send_prepare() error\n";
  16. }
  17. while(pg_connection_busy($db)); // busy wait: intended
  18. if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
  19. echo "pg_connection_status() error\n";
  20. }
  21. if (!($result = pg_get_result($db)))
  22. {
  23. echo "pg_get_result() error\n";
  24. }
  25. pg_free_result($result);
  26. if (!pg_send_execute($db, 'php_test', array(100))) {
  27. echo "pg_send_execute() error\n";
  28. }
  29. while(pg_connection_busy($db)); // busy wait: intended
  30. if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
  31. echo "pg_connection_status() error\n";
  32. }
  33. if (!($result = pg_get_result($db)))
  34. {
  35. echo "pg_get_result() error\n";
  36. }
  37. if (!($rows = pg_num_rows($result))) {
  38. echo "pg_num_rows() error\n";
  39. }
  40. for ($i=0; $i < $rows; $i++)
  41. {
  42. pg_fetch_array($result, $i, PGSQL_NUM);
  43. }
  44. for ($i=0; $i < $rows; $i++)
  45. {
  46. pg_fetch_object($result);
  47. }
  48. for ($i=0; $i < $rows; $i++)
  49. {
  50. pg_fetch_row($result, $i);
  51. }
  52. for ($i=0; $i < $rows; $i++)
  53. {
  54. pg_fetch_result($result, $i, 0);
  55. }
  56. pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
  57. pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
  58. pg_field_name($result, 0);
  59. pg_field_num($result, $field_name);
  60. pg_field_size($result, 0);
  61. pg_field_type($result, 0);
  62. pg_field_prtlen($result, 0);
  63. pg_field_is_null($result, 0);
  64. if (!pg_send_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);"))
  65. {
  66. echo "pg_send_prepare() error\n";
  67. }
  68. while(pg_connection_busy($db)); // busy wait: intended
  69. if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
  70. echo "pg_connection_status() error\n";
  71. }
  72. if (!($result = pg_get_result($db)))
  73. {
  74. echo "pg_get_result() error\n";
  75. }
  76. pg_free_result($result);
  77. if (!pg_send_execute($db, "php_test2", array(9999, "A'BC")))
  78. {
  79. echo "pg_send_execute() error\n";
  80. }
  81. while(pg_connection_busy($db)); // busy wait: intended
  82. if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
  83. echo "pg_connection_status() error\n";
  84. }
  85. if (!($result = pg_get_result($db)))
  86. {
  87. echo "pg_get_result() error\n";
  88. }
  89. pg_last_oid($result);
  90. pg_free_result($result);
  91. }
  92. pg_close($db);
  93. echo "OK";
  94. ?>
  95. --EXPECT--
  96. OK