mysqli_connect_oo_warnings.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. new mysqli()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. if (!get_current_user())
  9. die('skip: get_current_user() not supported');
  10. if (stristr(mysqli_get_client_info(), 'mysqlnd'))
  11. die("skip: test for libmysql (different error output when using php streams");
  12. ?>
  13. --FILE--
  14. <?php
  15. require_once("connect.inc");
  16. $myhost = 'invalidhost';
  17. $link = NULL;
  18. print "1) bail\n";
  19. if (!is_object($mysqli = new mysqli($myhost)) || ('mysqli' !== get_class($mysqli)))
  20. printf("[001] Expecting NULL, got %s/%s\n", gettype($mysqli), (is_object($mysqli)) ? var_export($mysqli, true) : $mysqli);
  21. print "2) be quiet\n";
  22. if (!is_object($mysqli = @new mysqli($myhost)) || ('mysqli' !== get_class($mysqli)))
  23. printf("[002] Expecting NULL, got %s/%s\n", gettype($mysqli), (is_object($mysqli)) ? var_export($mysqli, true) : $mysqli);
  24. var_dump(mysqli_connect_error());
  25. var_dump(mysqli_connect_errno());
  26. print "3) bail\n";
  27. if (false !== ($link = mysqli_connect($myhost))) {
  28. printf("[003] Expecting boolean/false, got %s/%s\n", gettype($link), $link);
  29. }
  30. print "4) be quiet\n";
  31. if (false !== ($link = @mysqli_connect($myhost))) {
  32. printf("[004] Expecting boolean/false, got %s/%s\n", gettype($link), $link);
  33. }
  34. var_dump(mysqli_connect_error());
  35. var_dump(mysqli_connect_errno());
  36. print "done!";
  37. ?>
  38. --EXPECTF--
  39. 1) bail
  40. Warning: mysqli::mysqli(): (HY000/200%d): %s
  41. 2) be quiet
  42. %s(%d) "%s"
  43. int(200%d)
  44. 3) bail
  45. Warning: mysqli_connect(): (HY000/200%d): %s
  46. 4) be quiet
  47. %s(%d) "%s"
  48. int(200%d)
  49. done!