1--TEST-- 2mysqli_connect() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $tmp = NULL; 14 $link = NULL; 15 16 /* we need to check, if the server allows anonymous login (empty user) */ 17 $tmp = @mysqli_connect('localhost'); 18 $anon_allow = (gettype($tmp) == "object"); 19 20 $exptype = ($anon_allow) ? "mysqli_object" : "false"; 21 22 $tmp = @mysqli_connect($link); 23 if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp != false)) { 24 printf("[002] Expecting %s, got %s/%s\n", $exptype, gettype($tmp), $tmp); 25 } 26 27 $tmp = @mysqli_connect($link, $link); 28 if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp != false)) { 29 printf("[003] Expecting %s, got %s/%s\n", $exptype, gettype($tmp), $tmp); 30 } 31 32 $tmp = @mysqli_connect($link, $link, $link); 33 if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp != false)) { 34 printf("[004] Expecting %s, got %s/%s\n", $exptype, gettype($tmp), $tmp); 35 } 36 37 $tmp = @mysqli_connect($link, $link, $link, $link); 38 if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp != false)) { 39 printf("[005] Expecting %s, got %s/%s\n", $exptype, gettype($tmp), $tmp); 40 } 41 42 $tmp = @mysqli_connect($link, $link, $link, $link, $link); 43 if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp != false)) { 44 printf("[006] Expecting %s, got %s/%s\n", $exptype, gettype($tmp), $tmp); 45 } 46 47 $tmp = @mysqli_connect($link, $link, $link, $link, $link, $link); 48 if (($anon_allow && gettype($tmp) != "object") || (!$anon_allow && $tmp != false)) { 49 printf("[007] Expecting %s, got %s/%s\n", $exptype, gettype($tmp), $tmp); 50 } 51 52 if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 53 printf("[008] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 54 $host, $user, $db, $port, $socket); 55 56 mysqli_close($link); 57 58 if ($link = mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) 59 printf("[009] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", 60 $host, $user . 'unknown_really', $db, $port, $socket); 61 62 if (false !== $link) 63 printf("[010] Expecting boolean/false, got %s/%s\n", gettype($link), $link); 64 65 // Run the following tests without an anoynmous MySQL user and use a password for the test user! 66 ini_set('mysqli.default_socket', $socket); 67 if (!is_object($link = mysqli_connect($host, $user, $passwd, $db, $port))) { 68 printf("[011] Usage of mysqli.default_socket failed\n") ; 69 } else { 70 if (!$res = mysqli_query($link, "SELECT 'mysqli.default_socket' AS 'testing'")) 71 printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 72 var_dump(mysqli_fetch_assoc($res)); 73 mysqli_free_result($res); 74 mysqli_close($link); 75 } 76 77 ini_set('mysqli.default_port', $port); 78 if (!is_object($link = mysqli_connect($host, $user, $passwd, $db))) { 79 printf("[013] Usage of mysqli.default_port failed\n") ; 80 } else { 81 if (!$res = mysqli_query($link, "SELECT 'mysqli.default_port' AS 'testing'")) 82 printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 83 var_dump(mysqli_fetch_assoc($res)); 84 mysqli_free_result($res); 85 mysqli_close($link); 86 } 87 88 ini_set('mysqli.default_pw', $passwd); 89 if (!is_object($link = mysqli_connect($host, $user))) { 90 printf("[015] Usage of mysqli.default_pw failed\n") ; 91 } else { 92 if (!$res = mysqli_query($link, "SELECT 'mysqli.default_pw' AS 'testing'")) 93 printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 94 var_dump(mysqli_fetch_assoc($res)); 95 mysqli_free_result($res); 96 mysqli_close($link); 97 } 98 99 ini_set('mysqli.default_user', $user); 100 if (!is_object($link = mysqli_connect($host))) { 101 printf("[017] Usage of mysqli.default_user failed\n") ; 102 } else { 103 if (!$res = mysqli_query($link, "SELECT 'mysqli.default_user' AS 'testing'")) 104 printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 105 var_dump(mysqli_fetch_array($res, MYSQLI_BOTH)); 106 mysqli_free_result($res); 107 mysqli_close($link); 108 } 109 110 ini_set('mysqli.default_host', $host); 111 if (!is_object($link = mysqli_connect())) { 112 printf("[019] Usage of mysqli.default_host failed\n") ; 113 } else { 114 if (!$res = mysqli_query($link, "SELECT 'mysqli.default_host' AS 'testing'")) 115 printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 116 var_dump(mysqli_fetch_array($res, MYSQLI_NUM)); 117 mysqli_free_result($res); 118 mysqli_close($link); 119 } 120 121 if ($IS_MYSQLND) { 122 ini_set('mysqli.default_host', 'p:' . $host); 123 if (!is_object($link = mysqli_connect())) { 124 printf("[021] Usage of mysqli.default_host (persistent) failed\n") ; 125 } else { 126 if (!$res = mysqli_query($link, "SELECT 'mysqli.default_host (persistent)' AS 'testing'")) 127 printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 128 $tmp = mysqli_fetch_assoc($res); 129 if ($tmp['testing'] !== 'mysqli.default_host (persistent)') { 130 printf("[023] Result looks strange - check manually, [%d] %s\n", 131 mysqli_errno($link), mysqli_error($link)); 132 var_dump($tmp); 133 } 134 mysqli_free_result($res); 135 mysqli_close($link); 136 } 137 138 ini_set('mysqli.default_host', 'p:'); 139 if (is_object($link = @mysqli_connect())) { 140 printf("[024] Usage of mysqli.default_host=p: did not fail\n") ; 141 mysqli_close($link); 142 } 143 } 144 145 print "done!"; 146?> 147--EXPECTF-- 148Warning: mysqli_connect(): (%s/%d): Access denied for user '%s'@'%s'%r( \(using password: \w+\)){0,1}%r in %s on line %d 149array(1) { 150 ["testing"]=> 151 string(21) "mysqli.default_socket" 152} 153array(1) { 154 ["testing"]=> 155 string(19) "mysqli.default_port" 156} 157array(1) { 158 ["testing"]=> 159 string(17) "mysqli.default_pw" 160} 161array(2) { 162 [0]=> 163 string(19) "mysqli.default_user" 164 ["testing"]=> 165 string(19) "mysqli.default_user" 166} 167array(1) { 168 [0]=> 169 string(19) "mysqli.default_host" 170} 171done! 172