PageRenderTime 32ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysqli/tests/mysqli_driver.php

http://github.com/facebook/hiphop-php
PHP | 102 lines | 78 code | 22 blank | 2 comment | 28 complexity | 462ac77677ff0be561310faf6a9c62e1 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. $test_table_name = 'test_mysqli_driver_table_1'; require("table.inc");
  3. if (!is_object($driver = new mysqli_driver()))
  4. printf("[001] Failed to create mysqli_driver object\n");
  5. $client_info = mysqli_get_client_info();
  6. if (($tmp = $driver->client_info) !== $client_info)
  7. printf("[002] Expecting %s/%s, got %s/%s\n",
  8. gettype($client_info), $client_info,
  9. gettype($tmp), $tmp);
  10. $client_version = mysqli_get_client_version();
  11. if (($tmp = $driver->client_version) !== $client_version)
  12. printf("[003] Expecting %s/%s, got %s/%s\n",
  13. gettype($client_version), $client_version,
  14. gettype($tmp), $tmp);
  15. if (!is_int($tmp = $driver->driver_version) || (0 == $tmp))
  16. printf("[004] Expecting int/any, got %s/%s\n",
  17. gettype($tmp), $tmp);
  18. $all_modes = array(MYSQLI_REPORT_INDEX, MYSQLI_REPORT_ERROR, MYSQLI_REPORT_STRICT,
  19. MYSQLI_REPORT_ALL, MYSQLI_REPORT_OFF);
  20. $report_mode = $driver->report_mode;
  21. if (!is_int($report_mode))
  22. printf("[005] Expecting int/any, got %s/%s\n",
  23. gettype($report_mode), $report_mode);
  24. if (!in_array($report_mode, $all_modes))
  25. printf("[006] Illegal report mode returned? Got %s, expected %s\n",
  26. $report_mode, implode(', ', $all_modes));
  27. $driver->report_mode = MYSQLI_REPORT_STRICT;
  28. $ok = false;
  29. try {
  30. if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
  31. printf("[007] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
  32. $host, $user . 'unknown_really', $db, $port, $socket);
  33. mysqli_close($link);
  34. } catch (mysqli_sql_exception $e) {
  35. $ok = true;
  36. if ('' == $e->getMessage())
  37. printf("[008] getMessage() has returned an empty string.\n");
  38. if ('' == $e->getCode())
  39. printf("[009] getCode() has returned an empty string.\n");
  40. if ('' == $e->getFile())
  41. printf("[010] getFile() has returned an empty string.\n");
  42. if ('' == $e->getLine())
  43. printf("[011] getLine() has returned an empty string.\n");
  44. $tmp = $e->getTrace();
  45. if (empty($tmp))
  46. printf("[012] getTrace() has returned an empty array.\n");
  47. if ('' == $e->getTraceAsString())
  48. printf("[013] getTraceAsString() has returned an empty string.\n");
  49. if ('' == $e->__toString())
  50. printf("[014] __toString() has returned an empty string.\n");
  51. }
  52. if (!$ok)
  53. printf("[015] Error reporting mode has not been switched to exceptions and or no exception thrown\n");
  54. $driver->report_mode = MYSQLI_REPORT_OFF;
  55. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  56. printf("[016] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  57. mysqli_query($link, "NO_SQL");
  58. mysqli_close($link);
  59. $driver->report_mode = MYSQLI_REPORT_ERROR;
  60. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  61. printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  62. mysqli_query($link, "NO_SQL");
  63. mysqli_close($link);
  64. if (MYSQLI_REPORT_ERROR !== $driver->report_mode)
  65. printf("[018] Error mode should be different\n");
  66. /* TODO - more report testing should go in here, but it's not really documented what behaviour is expected */
  67. $driver->report_mode = $report_mode;
  68. $reconnect = $driver->reconnect;
  69. if (!is_bool($reconnect))
  70. printf("[019] Expecting boolean/any, got %s/%s\n",
  71. gettype($reconnect), $reconnect);
  72. /* pointless, but I need more documentation */
  73. $driver->reconnect = true;
  74. $driver->reconnect = false;
  75. $driver->reconnect = $reconnect;
  76. if (!is_bool($embedded = $driver->embedded))
  77. printf("[020] Expecting boolean/any, got %s/%s\n",
  78. gettype($embedded), $embedded);
  79. print "done!";
  80. ?>