Seems like this is a pretty common error, but I can’t work it out. I’m running PHP 5.3.1 towards an
external MySQL server 5.5.8 – both installed with Phpmyadmin and running Windows Server 2k8R2.
When I try the following:
$connection = new mysqli("myhost.com:3306", "myUser", "myPwd", "myDB");
$result = $connection->prepare("SELECT * FROM tt_staff
WHERE crew_type = ?
AND inaktiv_vakt = 0
ORDER BY ansvarlig_vakt DESC, crew_type, navn_vakt");
$result->bind_param("s", $value);
$result->execute();
$result->bind_result($value, $name);
I get the ”
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host (…)”
I made sure that the Mysqli is enabled in the php.ini on the DB-server, but that’s also all I’ve done as I’ve been told this should work out-of-the-box. Since this is the first time I’m working with prepared statements there very well might be a simple typo error in there some place.
The problem is that MySQLi does not accept the port as part of the hostname but as a separate parameter. So I think this is how you should open your connection:
Or perhaps, do not give the port at all because 3306 is the default one.