mysql_connect()
and mysqli_connect()
use two different default ports from the php.ini file. I wouldn't guess that these would be different than the standard default 3306, but worth a check or try adding the path to the host url.
mysqli_connect:
mysqli mysqli_connect ( ... int $port = ini_get("mysqli.default_port") ... )
mysql_connect:
If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'. In SQL safe mode, this parameter is ignored and value 'localhost:3306' is always used.
Edit: I was wrong because I didn't read the manual page far enough.
I think your connection is fine, but you wouldn't want to check the object it returns as you have above. You'd want to use mysqli_connect_errno()
. Below is the example from PHP.net.
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
Note:
OO syntax only: If a connection
fails an object is still returned. To
check if the connection failed then
use either the mysqli_connect_error()
function or the mysqli->connect_error
property as in the preceding examples.
Source