PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysqli/tests/mysqli_stmt_execute_stored_proc_next_result.php

http://github.com/facebook/hiphop-php
PHP | 110 lines | 80 code | 28 blank | 2 comment | 26 complexity | 94d619edbc7692d43932889ca2999c16 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. require_once('connect.inc');
  3. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  4. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  5. $host, $user, $db, $port, $socket);
  6. }
  7. if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
  8. printf("[003] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
  9. if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25)) BEGIN SELECT ver_in AS _ver_out; END;')) {
  10. // one result set
  11. if (!$stmt = mysqli_prepare($link, 'CALL p(?)'))
  12. printf("[005] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  13. $version = 'myversion';
  14. if (!mysqli_stmt_bind_param($stmt, 's', $version))
  15. printf("[006] Cannot bind input parameter, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  16. if (!mysqli_stmt_execute($stmt))
  17. printf("[007] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  18. $version = 'unknown';
  19. if (!mysqli_stmt_bind_result($stmt, $version) ||
  20. !mysqli_stmt_fetch($stmt))
  21. printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  22. if ($version !== "myversion")
  23. printf("[009] Results seem wrong, got %s, [%d] %s\n",
  24. $version,
  25. mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  26. mysqli_stmt_free_result($stmt);
  27. printf("[010] More results: %s\n", (mysqli_more_results($link)) ? "yes" : "no");
  28. printf("[011] Next result: %s\n", (mysqli_next_result($link)) ? "yes" : "no");
  29. if (!mysqli_stmt_close($stmt))
  30. printf("[012] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  31. if (!$link->query("SELECT 1"))
  32. printf("[013] [%d] %s\n", $link->errno, $link->error);
  33. } else {
  34. printf("[004] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
  35. }
  36. if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
  37. printf("[014] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
  38. if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25)) BEGIN SELECT ver_in AS _ver_out; SELECT 1 AS _more; END;')) {
  39. // two result sets
  40. if (!$stmt = mysqli_prepare($link, 'CALL p(?)'))
  41. printf("[015] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  42. $version = 'myversion';
  43. if (!mysqli_stmt_bind_param($stmt, 's', $version))
  44. printf("[016] Cannot bind input parameter, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  45. if (!mysqli_stmt_execute($stmt))
  46. printf("[017] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  47. $version = NULL;
  48. if (!mysqli_stmt_bind_result($stmt, $version) ||
  49. !mysqli_stmt_fetch($stmt))
  50. printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  51. if ($version !== "myversion")
  52. printf("[019] Results seem wrong, got %s, [%d] %s\n",
  53. $version,
  54. mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  55. if (!mysqli_more_results($link) || !mysqli_next_result($link))
  56. printf("[020] [%d] %s\n", $link->errno, $link->error);
  57. $more = NULL;
  58. if (!mysqli_stmt_bind_result($stmt, $more) ||
  59. !mysqli_stmt_fetch($stmt))
  60. printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  61. if ($more !== 1)
  62. printf("[022] Results seem wrong, got %s, [%d] %s\n",
  63. $more,
  64. mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  65. if (!mysqli_stmt_close($stmt))
  66. printf("[023] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  67. if (!$link->query("SELECT 1"))
  68. printf("[024] [%d] %s\n", $link->errno, $link->error);
  69. } else {
  70. printf("[025] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
  71. }
  72. mysqli_close($link);
  73. print "done!";
  74. ?>
  75. <?php error_reporting(0); ?>
  76. <?php
  77. require_once("connect.inc");
  78. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  79. printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  80. @mysqli_query($link, 'DROP PROCEDURE IF EXISTS p');
  81. mysqli_close($link);
  82. ?>