PageRenderTime 42ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/slow/ext_mysql/connect.inc

http://github.com/facebook/hiphop-php
PHP | 97 lines | 77 code | 14 blank | 6 comment | 17 complexity | cbb7d092f0d7f9df79df43c829ae519f 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. 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. function create_test_table($suffix = '') {
  49. $name = "test_$suffix";
  50. mysql_select_db($GLOBALS['db']);
  51. mysql_query("drop table $name");
  52. $success = (bool)mysql_query(
  53. "create table $name (id int not null auto_increment,".
  54. " name varchar(255) not null, primary key (id)) ".
  55. "engine=innodb"
  56. );
  57. if (!$success) {
  58. var_dump(mysql_error());
  59. }
  60. return $success;
  61. }
  62. /*
  63. Default values are "localhost", "root", database "test" and empty password.
  64. Change the MYSQL_TEST_* environment values if you want to use another configuration.
  65. */
  66. $host = getenv("MYSQL_TEST_HOST") ? getenv("MYSQL_TEST_HOST") : "localhost";
  67. $port = getenv("MYSQL_TEST_PORT") ? getenv("MYSQL_TEST_PORT") : 3306;
  68. $user = getenv("MYSQL_TEST_USER") ? getenv("MYSQL_TEST_USER") : "root";
  69. $passwd = getenv("MYSQL_TEST_PASSWD") ? getenv("MYSQL_TEST_PASSWD") : "";
  70. $db = getenv("MYSQL_TEST_DB") ? getenv("MYSQL_TEST_DB") : "test";
  71. $engine = getenv("MYSQL_TEST_ENGINE") ? getenv("MYSQL_TEST_ENGINE") : "MyISAM";
  72. $socket = getenv("MYSQL_TEST_SOCKET") ? getenv("MYSQL_TEST_SOCKET") : null;
  73. $skip_on_connect_failure = getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") ? getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") : true;
  74. $connect_flags = getenv("MYSQL_TEST_CONNECT_FLAGS") ? (int)getenv("MYSQL_TEST_CONNECT_FLAGS") : 0;
  75. if ($socket) {
  76. ini_set('mysql.default_socket', $socket);
  77. }
  78. /* Development setting: test experimal features and/or feature requests that never worked before? */
  79. $TEST_EXPERIMENTAL = (in_array(getenv("MYSQL_TEST_EXPERIMENTAL"), array(0, 1))) ?
  80. ((1 == getenv("MYSQL_TEST_EXPERIMENTAL")) ? true : false) :
  81. false;
  82. $IS_MYSQLND = stristr(mysql_get_client_info(), "mysqlnd");
  83. ?>