Warning: MySQLi_Connect(): Unknown MySQL Server Host

Warning: mysqli_connect(): Unknown MySQL server host

The port number must be a separate argument:

$link = mysqli_connect('host', 'user', 'pass', 'db', 5306);

PHP: Unknown MySQL server host with mysqli

take out the p: like this:

$dbh = new mysqli($host, $username, $password, $db) 
or die('no connection to server');

Unknown MySQL server host

You might be passing the clouddb.myhost.gr:3306 all together, on the mysqlcli, the port have its own parameter:

mysql:host=clouddb.myhost.gr;port=3306;

Related question:

SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)

Can't connect using mysqli_connect, but mysql_connect works..?

Either you have misinterpreted the instructions from 1&1, or else they made a mistake.

Read the manual page for mysqli_connect(). It shows that the first argument should be the hostname, either by name or IP. Do not include the socket in that argument.

You can optionally specify the socket file as the sixth argument.

/* WRONG */
mysqli_connect('localhost/tmp/mysql5.sock', ... );

/* WRONG */
mysqli_connect('localhost:/tmp/mysql5.sock', ... );

/* RIGHT */
mysqli_connect('localhost', $db_username, $db_password, $db_database, null, '/tmp/mysql5.sock');

Also, I wonder why they even require you to specify the socket. They should define a default in the host's php.ini file, so you don't have to. Unless perhaps they're running multiple instances of mysqld on the same host.

PHP MySql unknown server host

I had a similar issue when I started out using mysqli. If you need to include the port, it has its own place in mysqli_connect.

$link = mysqli_connect("127.0.0.1", "username", "password", "dbname", 3306);

should work better for you. But I believe 3306 is the default port, so you may be able to just leave it off.

Unknown MySQL server host

This is usually the case when name resolving doesn't work on the host. If your connect destination is always the same, you might want to use its IP address for connecting instead.



Related Topics



Leave a reply



Submit