mysqli_driver.phpt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --TEST--
  2. mysqli_driver class
  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("table.inc");
  12. if (!is_object($driver = new mysqli_driver()))
  13. printf("[001] Failed to create mysqli_driver object\n");
  14. $client_info = mysqli_get_client_info();
  15. if (($tmp = $driver->client_info) !== $client_info)
  16. printf("[002] Expecting %s/%s, got %s/%s\n",
  17. gettype($client_info), $client_info,
  18. gettype($tmp), $tmp);
  19. $client_version = mysqli_get_client_version();
  20. if (($tmp = $driver->client_version) !== $client_version)
  21. printf("[003] Expecting %s/%s, got %s/%s\n",
  22. gettype($client_version), $client_version,
  23. gettype($tmp), $tmp);
  24. if (!is_int($tmp = $driver->driver_version) || (0 == $tmp))
  25. printf("[004] Expecting int/any, got %s/%s\n",
  26. gettype($tmp), $tmp);
  27. $all_modes = array(MYSQLI_REPORT_INDEX, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_STRICT,
  28. MYSQLI_REPORT_ALL, MYSQLI_REPORT_OFF);
  29. $report_mode = $driver->report_mode;
  30. if (!is_int($report_mode))
  31. printf("[005] Expecting int/any, got %s/%s\n",
  32. gettype($report_mode), $report_mode);
  33. if (!in_array($report_mode, $all_modes))
  34. printf("[006] Illegal report mode returned? Got %s, expected %s\n",
  35. $report_mode, implode(', ', $all_modes));
  36. $driver->report_mode = MYSQLI_REPORT_STRICT;
  37. $ok = false;
  38. try {
  39. if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
  40. printf("[007] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
  41. $host, $user . 'unknown_really', $db, $port, $socket);
  42. mysqli_close($link);
  43. } catch (mysqli_sql_exception $e) {
  44. $ok = true;
  45. if ('' == $e->getMessage())
  46. printf("[008] getMessage() has returned an empty string.\n");
  47. if ('' == $e->getCode())
  48. printf("[009] getCode() has returned an empty string.\n");
  49. if ('' == $e->getFile())
  50. printf("[010] getFile() has returned an empty string.\n");
  51. if ('' == $e->getLine())
  52. printf("[011] getLine() has returned an empty string.\n");
  53. $tmp = $e->getTrace();
  54. if (empty($tmp))
  55. printf("[012] getTrace() has returned an empty array.\n");
  56. if ('' == $e->getTraceAsString())
  57. printf("[013] getTraceAsString() has returned an empty string.\n");
  58. if ('' == $e->__toString())
  59. printf("[014] __toString() has returned an empty string.\n");
  60. }
  61. if (!$ok)
  62. printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n");
  63. $driver->report_mode = MYSQLI_REPORT_OFF;
  64. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  65. printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  66. mysqli_query($link, "NO_SQL");
  67. mysqli_close($link);
  68. $driver->report_mode = MYSQLI_REPORT_ERROR;
  69. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  70. printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  71. mysqli_query($link, "NO_SQL");
  72. mysqli_close($link);
  73. if (MYSQLI_REPORT_ERROR !== $driver->report_mode)
  74. printf("[018] Error mode should be different\n");
  75. /* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */
  76. $driver->report_mode = $report_mode;
  77. $reconnect = $driver->reconnect;
  78. if (!is_bool($reconnect))
  79. printf("[019] Expecting boolean/any, got %s/%s\n",
  80. gettype($reconnect), $reconnect);
  81. /* pointless, but I need more documentation */
  82. $driver->reconnect = true;
  83. $driver->reconnect = false;
  84. $driver->reconnect = $reconnect;
  85. if (!is_bool($embedded = $driver->embedded))
  86. printf("[020] Expecting boolean/any, got %s/%s\n",
  87. gettype($embedded), $embedded);
  88. print "done!";
  89. ?>
  90. --EXPECTF--
  91. Warning: mysqli_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'NO_SQL' at line 1 in %s on line %d
  92. done!