Back to index

php5  5.3.10
connect.inc
Go to the documentation of this file.
00001 <?php
00002 if (!function_exists('sys_get_temp_dir')) {
00003        function sys_get_temp_dir() {
00004 
00005               if (!empty($_ENV['TMP']))
00006                      return realpath( $_ENV['TMP'] );
00007               if (!empty($_ENV['TMPDIR']))
00008                      return realpath( $_ENV['TMPDIR'] );
00009               if (!empty($_ENV['TEMP']))
00010                      return realpath( $_ENV['TEMP'] );
00011 
00012               $temp_file = tempnam(md5(uniqid(rand(), TRUE)), '');
00013               if ($temp_file) {
00014                      $temp_dir = realpath(dirname($temp_file));
00015                      unlink($temp_file);
00016                      return $temp_dir;
00017               }
00018               return FALSE;
00019        }
00020 }
00021 
00022 if (!function_exists('my_mysql_connect')) {
00023        /* wrapper to simplify test porting */
00024        function my_mysql_connect($host, $user, $passwd, $db, $port, $socket, $flags = NULL, $persistent = false) {
00025               global $connect_flags;
00026 
00027               $flags = ($flags === NULL) ? $connect_flags : $flags;
00028 
00029               if ($socket)
00030                      $host = sprintf("%s:%s", $host, $socket);
00031               else if ($port)
00032                      $host = sprintf("%s:%s", $host, $port);
00033 
00034               if ($persistent) {
00035                      $link = mysql_pconnect($host, $user, $passwd, $flags);
00036               } else {
00037                       $link = mysql_connect($host, $user, $passwd, true, $flags);
00038               }
00039 
00040               if (!$link) {
00041                      printf("[000-a] Cannot connect using host '%s', user '%s', password '****', persistent = %d, [%d] %s\n",
00042                             $host, $user, ($persistent) ? 1 : 0,
00043                             mysql_errno(), mysql_error());
00044                      return false;
00045               }
00046 
00047               if (!mysql_select_db($db, $link)) {
00048                      printf("[000-b] [%d] %s\n", mysql_errno($link), mysql_error($link));
00049                      return false;
00050               }
00051 
00052               return $link;
00053        }
00054 } else {
00055        printf("skip Eeeek/BUG/FIXME - connect.inc included twice! skipif bug?\n");
00056 }
00057 
00058 /*
00059 Default values are "localhost", "root", database "test" and empty password.
00060 Change the MYSQL_TEST_* environment values if you want to use another configuration.
00061 */
00062 
00063 $host         = getenv("MYSQL_TEST_HOST") ? getenv("MYSQL_TEST_HOST") : "localhost";
00064 $port         = getenv("MYSQL_TEST_PORT") ? getenv("MYSQL_TEST_PORT") : 3306;
00065 $user         = getenv("MYSQL_TEST_USER") ? getenv("MYSQL_TEST_USER") : "root";
00066 $passwd       = getenv("MYSQL_TEST_PASSWD")      ? getenv("MYSQL_TEST_PASSWD")      : "";
00067 
00068 $db                  = getenv("MYSQL_TEST_DB")   ? getenv("MYSQL_TEST_DB")   : "test";
00069 $engine       = getenv("MYSQL_TEST_ENGINE")      ? getenv("MYSQL_TEST_ENGINE")      : "MyISAM";
00070 $socket       = getenv("MYSQL_TEST_SOCKET")      ? getenv("MYSQL_TEST_SOCKET")      : null;
00071 $skip_on_connect_failure  = getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") ? getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") : true;
00072 $connect_flags = getenv("MYSQL_TEST_CONNECT_FLAGS") ? (int)getenv("MYSQL_TEST_CONNECT_FLAGS") : 0;
00073 if ($socket) {
00074        ini_set('mysql.default_socket', $socket);
00075 }
00076 /* Development setting: test experimal features and/or feature requests that never worked before? */
00077 $TEST_EXPERIMENTAL = (in_array(getenv("MYSQL_TEST_EXPERIMENTAL"), array(0, 1))) ?
00078        ((1 == getenv("MYSQL_TEST_EXPERIMENTAL")) ? true : false) :
00079        false;
00080 
00081 $IS_MYSQLND = stristr(mysql_get_client_info(), "mysqlnd");
00082 ?>