mysqli_stmt_errno.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. mysqli_stmt_errno()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. require('table.inc');
  13. if (!$stmt = mysqli_stmt_init($link))
  14. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  15. // properly initialized?
  16. if (0 !== ($tmp = mysqli_stmt_errno($stmt)))
  17. printf("[004] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
  18. if (mysqli_stmt_prepare($stmt, "SELECT i_do_not_exist_believe_me FROM test ORDER BY id"))
  19. printf("[005] Statement should have failed!\n");
  20. // set after error server?
  21. if (0 === ($tmp = mysqli_stmt_errno($stmt)))
  22. printf("[006] Expecting int/any non zero, got %s/%s\n", gettype($tmp), $tmp);
  23. if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id"))
  24. printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  25. // reset after error & success
  26. if (0 != ($tmp = mysqli_stmt_errno($stmt)))
  27. printf("[008] Expecting zero, got %s/%s\n", gettype($tmp), $tmp);
  28. mysqli_kill($link, mysqli_thread_id($link));
  29. if (true === ($tmp = mysqli_stmt_execute($stmt)))
  30. printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  31. // set after client error
  32. if (0 === ($tmp = mysqli_stmt_errno($stmt)))
  33. printf("[010] Expecting int/any non zero, got %s/%s\n", gettype($tmp), $tmp);
  34. mysqli_stmt_close($stmt);
  35. try {
  36. mysqli_stmt_errno($stmt);
  37. } catch (Error $exception) {
  38. echo $exception->getMessage() . "\n";
  39. }
  40. mysqli_close($link);
  41. print "done!";
  42. ?>
  43. --CLEAN--
  44. <?php
  45. require_once("clean_table.inc");
  46. ?>
  47. --EXPECT--
  48. mysqli_stmt object is already closed
  49. done!