connect.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. if (!function_exists('sys_get_temp_dir')) {
  3. function sys_get_temp_dir() {
  4. if (!empty($_ENV['TMP']))
  5. return realpath( $_ENV['TMP'] );
  6. if (!empty($_ENV['TMPDIR']))
  7. return realpath( $_ENV['TMPDIR'] );
  8. if (!empty($_ENV['TEMP']))
  9. return realpath( $_ENV['TEMP'] );
  10. $temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
  11. if ($temp_file) {
  12. $temp_dir = realpath(dirname($temp_file));
  13. unlink($temp_file);
  14. return $temp_dir;
  15. }
  16. return FALSE;
  17. }
  18. }
  19. if (!function_exists('my_mysql_connect')) {
  20. /* wrapper to simplify test porting */
  21. function my_mysql_connect($host, $user, $passwd, $db, $port, $socket, $flags = NULL, $persistent = false) {
  22. global $connect_flags;
  23. $flags = ($flags === NULL) ? $connect_flags : $flags;
  24. if ($socket)
  25. $host = sprintf("%s:%s", $host, $socket);
  26. else if ($port)
  27. $host = sprintf("%s:%s", $host, $port);
  28. if ($persistent) {
  29. $link = mysql_pconnect($host, $user, $passwd, $flags);
  30. } else {
  31. $link = mysql_connect($host, $user, $passwd, true, $flags);
  32. }
  33. if (!$link) {
  34. printf("[000-a] Cannot connect using host '%s', user '%s', password '****', persistent = %d, [%d] %s\n",
  35. $host, $user, ($persistent) ? 1 : 0,
  36. mysql_errno(), mysql_error());
  37. return false;
  38. }
  39. if (!mysql_select_db($db, $link)) {
  40. printf("[000-b] [%d] %s\n", mysql_errno($link), mysql_error($link));
  41. return false;
  42. }
  43. return $link;
  44. }
  45. } else {
  46. printf("skip Eeeek/BUG/FIXME - connect.inc included twice! skipif bug?\n");
  47. }
  48. /*
  49. Default values are "localhost", "root", database "test" and empty password.
  50. Change the MYSQL_TEST_* environment values if you want to use another configuration.
  51. */
  52. $host = getenv("MYSQL_TEST_HOST") ? getenv("MYSQL_TEST_HOST") : "localhost";
  53. $port = getenv("MYSQL_TEST_PORT") ? getenv("MYSQL_TEST_PORT") : 3306;
  54. $user = getenv("MYSQL_TEST_USER") ? getenv("MYSQL_TEST_USER") : "root";
  55. $passwd = getenv("MYSQL_TEST_PASSWD") ? getenv("MYSQL_TEST_PASSWD") : "";
  56. $db = getenv("MYSQL_TEST_DB") ? getenv("MYSQL_TEST_DB") : "test";
  57. $engine = getenv("MYSQL_TEST_ENGINE") ? getenv("MYSQL_TEST_ENGINE") : "MyISAM";
  58. $socket = getenv("MYSQL_TEST_SOCKET") ? getenv("MYSQL_TEST_SOCKET") : null;
  59. $skip_on_connect_failure = getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") ? getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") : true;
  60. $connect_flags = getenv("MYSQL_TEST_CONNECT_FLAGS") ? (int)getenv("MYSQL_TEST_CONNECT_FLAGS") : 0;
  61. if ($socket) {
  62. ini_set('mysql.default_socket', $socket);
  63. }
  64. /* Development setting: test experimal features and/or feature requests that never worked before? */
  65. $TEST_EXPERIMENTAL = (in_array(getenv("MYSQL_TEST_EXPERIMENTAL"), array(0, 1))) ?
  66. ((1 == getenv("MYSQL_TEST_EXPERIMENTAL")) ? true : false) :
  67. false;
  68. $IS_MYSQLND = stristr(mysql_get_client_info(), "mysqlnd");
  69. ?>