mysqli_stmt_error.phpt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. mysqli_stmt_error()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. $tmp = NULL;
  13. $link = NULL;
  14. if (!is_null($tmp = @mysqli_stmt_error()))
  15. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. if (!is_null($tmp = @mysqli_stmt_error($link)))
  17. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  18. require('table.inc');
  19. if (!$stmt = mysqli_stmt_init($link))
  20. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  21. // properly initialized?
  22. if ('' !== ($tmp = mysqli_stmt_error($stmt)))
  23. printf("[004] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  24. if (mysqli_stmt_prepare($stmt, "SELECT i_do_not_exist_believe_me FROM test ORDER BY id"))
  25. printf("[005] Statement should have failed!\n");
  26. // set after error server?
  27. if ('' === ($tmp = mysqli_stmt_error($stmt)))
  28. printf("[006] Expecting string/any non empty, got %s/%s\n", gettype($tmp), $tmp);
  29. if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id"))
  30. printf("[007] [%d] %s\n", mysqli_stmt_error($stmt), mysqli_stmt_error($stmt));
  31. // reset after error & success
  32. if ('' !== ($tmp = mysqli_stmt_error($stmt)))
  33. printf("[008] Expecting empty string, got %s/%s\n", gettype($tmp), $tmp);
  34. mysqli_kill($link, mysqli_thread_id($link));
  35. if (true === ($tmp = mysqli_stmt_execute($stmt)))
  36. printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  37. // set after client error
  38. if ('' === ($tmp = mysqli_stmt_error($stmt)))
  39. printf("[010] Execting string/any non empty, got %s/%s\n", gettype($tmp), $tmp);
  40. mysqli_stmt_close($stmt);
  41. if (NULL !== ($tmp = mysqli_stmt_error($stmt)))
  42. printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  43. mysqli_close($link);
  44. print "done!";
  45. ?>
  46. --CLEAN--
  47. <?php
  48. require_once("clean_table.inc");
  49. ?>
  50. --EXPECTF--
  51. Warning: mysqli_stmt_error(): Couldn't fetch mysqli_stmt in %s on line %d
  52. done!