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