bug44897.phpt 2.7 KB

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