mysqli_driver.phpt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. --TEST--
  2. mysqli_driver class
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once('connect.inc');
  12. if (!is_object($driver = new mysqli_driver())) {
  13. printf("[001] Failed to create mysqli_driver object\n");
  14. }
  15. $client_info = mysqli_get_client_info();
  16. if (($tmp = $driver->client_info) !== $client_info) {
  17. printf("[002] Expecting %s/%s, got %s/%s\n",
  18. gettype($client_info), $client_info,
  19. gettype($tmp), $tmp);
  20. }
  21. $client_version = mysqli_get_client_version();
  22. if (($tmp = $driver->client_version) !== $client_version) {
  23. printf("[003] Expecting %s/%s, got %s/%s\n",
  24. gettype($client_version), $client_version,
  25. gettype($tmp), $tmp);
  26. }
  27. $all_modes = [
  28. MYSQLI_REPORT_ALL,
  29. MYSQLI_REPORT_STRICT,
  30. MYSQLI_REPORT_STRICT|MYSQLI_REPORT_ERROR,
  31. MYSQLI_REPORT_STRICT|MYSQLI_REPORT_INDEX,
  32. MYSQLI_REPORT_ERROR,
  33. MYSQLI_REPORT_ERROR|MYSQLI_REPORT_INDEX,
  34. MYSQLI_REPORT_INDEX,
  35. MYSQLI_REPORT_OFF
  36. ];
  37. $report_mode = $driver->report_mode;
  38. if (!is_int($report_mode)) {
  39. printf("[005] Expecting int/any, got %s/%s\n",
  40. gettype($report_mode), $report_mode);
  41. }
  42. if (!in_array($report_mode, $all_modes)) {
  43. printf("[006] Illegal report mode returned? Got %s, expected %s\n",
  44. $report_mode, implode(', ', $all_modes));
  45. }
  46. $driver->report_mode = MYSQLI_REPORT_STRICT;
  47. $ok = false;
  48. try {
  49. if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) {
  50. printf("[007] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
  51. $host, $user . 'unknown_really', $db, $port, $socket);
  52. }
  53. mysqli_close($link);
  54. } catch (mysqli_sql_exception $e) {
  55. $ok = true;
  56. if ('' == $e->getMessage()) {
  57. printf("[008] getMessage() has returned an empty string.\n");
  58. }
  59. if ('' == $e->getCode()) {
  60. printf("[009] getCode() has returned an empty string.\n");
  61. }
  62. if ('' == $e->getFile()) {
  63. printf("[010] getFile() has returned an empty string.\n");
  64. }
  65. if ('' == $e->getLine()) {
  66. printf("[011] getLine() has returned an empty string.\n");
  67. }
  68. if ([] == $e->getTrace()) {
  69. printf("[012] getTrace() has returned an empty array.\n");
  70. }
  71. if ('' == $e->getTraceAsString()) {
  72. printf("[013] getTraceAsString() has returned an empty string.\n");
  73. }
  74. if ('' == $e->__toString()) {
  75. printf("[014] __toString() has returned an empty string.\n");
  76. }
  77. }
  78. if (!$ok) {
  79. printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n");
  80. }
  81. $driver->report_mode = MYSQLI_REPORT_OFF;
  82. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  83. printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  84. }
  85. mysqli_query($link, "NO_SQL");
  86. mysqli_close($link);
  87. $driver->report_mode = MYSQLI_REPORT_ERROR;
  88. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  89. printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  90. }
  91. mysqli_query($link, "NO_SQL");
  92. mysqli_close($link);
  93. if (MYSQLI_REPORT_ERROR !== $driver->report_mode) {
  94. printf("[018] Error reporting mode should be different\n");
  95. }
  96. /* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */
  97. $driver->report_mode = $report_mode;
  98. $reconnect = $driver->reconnect;
  99. if (!is_bool($reconnect)) {
  100. printf("[019] Expecting boolean/any, got %s/%s\n",
  101. gettype($reconnect), $reconnect);
  102. }
  103. /* pointless, but I need more documentation */
  104. $driver->reconnect = true;
  105. $driver->reconnect = false;
  106. $driver->reconnect = $reconnect;
  107. print "done!";
  108. ?>
  109. --EXPECTF--
  110. 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
  111. done!