bug44897.phpt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. Bug #44879 (failed to prepare statement)
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. if (!stristr(mysqli_get_client_info(), 'mysqlnd'))
  8. die("skip: only available in mysqlnd");
  9. require_once('skipifconnectfailure.inc');
  10. require_once('connect.inc');
  11. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  12. die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error()));
  13. }
  14. if (mysqli_get_server_version($link) <= 50000) {
  15. die(sprintf('skip Needs MySQL 5.0+, found version %d.', mysqli_get_server_version($link)));
  16. }
  17. ?>
  18. --FILE--
  19. <?php
  20. require_once("table.inc");
  21. if (!$link->query('DROP PROCEDURE IF EXISTS p'))
  22. printf("[001] [%d] %s\n", $link->errno, $link->error);
  23. if (!$link->query('CREATE PROCEDURE p(IN new_id INT, IN new_label CHAR(1)) BEGIN INSERT INTO test(id, label) VALUES (new_id, new_label); SELECT new_label; END;'))
  24. printf("[002] [%d] %s\n", $link->errno, $link->error);
  25. $new_id = 100;
  26. $new_label = 'z';
  27. if (!$stmt = $link->prepare('CALL p(?, ?)'))
  28. printf("[003] [%d] %s\n", $link->errno, $link->error);
  29. if (!$stmt->bind_param('is', $new_id, $new_label) || !$stmt->execute())
  30. printf("[004] [%d] %s\n", $stmt->errno, $stmt->error);
  31. $out_new_label = null;
  32. if (!$stmt->bind_result($out_new_label) || !$stmt->fetch())
  33. printf("[005] [%d] %s\n", $stmt->errno, $stmt->error);
  34. if ($out_new_label != $new_label)
  35. printf("[006] IN value and returned value differ. Expecting %s/%s got %s/%s\n",
  36. $new_label, gettype($new_label), $out_new_label, gettype($out_new_label));
  37. $stmt->close();
  38. $stmt2 = $link->prepare('SELECT label FROM test WHERE id = ?');
  39. if (!is_object($stmt2)) {
  40. printf("[007] Failed to create new statement object, [%d] %s\n",
  41. $link->errno, $link->error);
  42. } else {
  43. if (!$stmt2->bind_param("i", $new_id) || !$stmt2->execute())
  44. printf("[008] [%d] %s\n", $stmt2->errno, $stmt2->error);
  45. $out_new_label = null;
  46. if (!$stmt2->bind_result($out_new_label) || !$stmt2->fetch())
  47. printf("[009] [%d] %s\n", $stmt2->errno, $stmt2->error);
  48. if ($out_new_label != $new_label)
  49. printf("[010] IN value and returned value differ. Expecting %s/%s got %s/%s\n",
  50. $new_label, gettype($new_label), $out_new_label, gettype($out_new_label));
  51. }
  52. $link->close();
  53. print "done!";
  54. ?>
  55. --CLEAN--
  56. <?php
  57. require_once("connect.inc");
  58. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  59. printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  60. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  61. printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  62. mysqli_query($link, "DROP PROCEDURE IF EXISTS p");
  63. mysqli_close($link);
  64. ?>
  65. --EXPECT--
  66. done!