mysqli_stmt_execute.phpt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. --TEST--
  2. mysqli_stmt_execute()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  9. die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error()));
  10. }
  11. if (mysqli_get_server_version($link) <= 40100) {
  12. die(sprintf('skip Needs MySQL 4.1+, found version %d.', mysqli_get_server_version($link)));
  13. }
  14. ?>
  15. --FILE--
  16. <?php
  17. require_once("connect.inc");
  18. require('table.inc');
  19. if (!$stmt = mysqli_stmt_init($link))
  20. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  21. // stmt object status test
  22. try {
  23. mysqli_stmt_execute($stmt);
  24. } catch (Error $exception) {
  25. echo $exception->getMessage() . "\n";
  26. }
  27. if (mysqli_stmt_prepare($stmt, "SELECT i_do_not_exist_believe_me FROM test ORDER BY id"))
  28. printf("[005] Statement should have failed!\n");
  29. // stmt object status test
  30. try {
  31. mysqli_stmt_execute($stmt);
  32. } catch (Error $exception) {
  33. echo $exception->getMessage() . "\n";
  34. }
  35. if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1"))
  36. printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  37. if (true !== ($tmp = mysqli_stmt_execute($stmt)))
  38. printf("[008] Expecting boolean/true, got %s/%s. [%d] %s\n",
  39. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  40. if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)"))
  41. printf("[009] [%d] %s\n", mysqli_stmt_execute($stmt), mysqli_stmt_execute($stmt));
  42. // no input variables bound
  43. if (false !== ($tmp = mysqli_stmt_execute($stmt)))
  44. printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  45. $id = 100;
  46. $label = "z";
  47. if (!mysqli_stmt_bind_param($stmt, "is", $id, $label))
  48. printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  49. if (true !== ($tmp = mysqli_stmt_execute($stmt)))
  50. printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  51. // calling reset between executions
  52. mysqli_stmt_close($stmt);
  53. if (!$stmt = mysqli_stmt_init($link))
  54. printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  55. if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT ?"))
  56. printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  57. $limit = 1;
  58. if (!mysqli_stmt_bind_param($stmt, "i", $limit))
  59. printf("[015] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  60. if (true !== ($tmp = mysqli_stmt_execute($stmt)))
  61. printf("[016] Expecting boolean/true, got %s/%s. [%d] %s\n",
  62. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  63. $id = null;
  64. if (!mysqli_stmt_bind_result($stmt, $id) || !mysqli_stmt_fetch($stmt))
  65. printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  66. if ($id !== 1)
  67. printf("[018] Expecting int/1 got %s/%s\n", gettype($id), $id);
  68. if (true !== ($tmp = mysqli_stmt_reset($stmt)))
  69. printf("[019] Expecting boolean/true, got %s/%s. [%d] %s\n",
  70. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  71. if (true !== ($tmp = mysqli_stmt_execute($stmt)))
  72. printf("[020] Expecting boolean/true after reset to prepare status, got %s/%s. [%d] %s\n",
  73. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  74. $id = null;
  75. if (!mysqli_stmt_fetch($stmt))
  76. printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  77. if ($id !== 1)
  78. printf("[022] Expecting int/1 got %s/%s\n", gettype($id), $id);
  79. mysqli_stmt_close($stmt);
  80. if (!$stmt = mysqli_stmt_init($link))
  81. printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  82. if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1"))
  83. printf("[024] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  84. if (true !== ($tmp = mysqli_stmt_execute($stmt)))
  85. printf("[025] Expecting boolean/true, got %s/%s. [%d] %s\n",
  86. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  87. if (true !== ($tmp = mysqli_stmt_reset($stmt)))
  88. printf("[026] Expecting boolean/true, got %s/%s. [%d] %s\n",
  89. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  90. var_dump(mysqli_stmt_execute($stmt));
  91. var_dump(mysqli_stmt_fetch($stmt));
  92. mysqli_kill($link, mysqli_thread_id($link));
  93. if (false !== ($tmp = mysqli_stmt_execute($stmt)))
  94. printf("[027] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  95. mysqli_stmt_close($stmt);
  96. try {
  97. mysqli_stmt_execute($stmt);
  98. } catch (Error $exception) {
  99. echo $exception->getMessage() . "\n";
  100. }
  101. mysqli_close($link);
  102. print "done!";
  103. ?>
  104. --CLEAN--
  105. <?php
  106. require_once("clean_table.inc");
  107. ?>
  108. --EXPECT--
  109. mysqli_stmt object is not fully initialized
  110. mysqli_stmt object is not fully initialized
  111. bool(true)
  112. bool(true)
  113. [027] Expecting boolean/false, got boolean/1
  114. mysqli_stmt object is already closed
  115. done!