26async_query_prepared.phpt 2.8 KB

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