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
PHP Ternary Operator Clarification
Google Recaptcha - Keep Getting 'Incorrect-Captcha-Sol'
Key of Null Variable Equals Null Not Error
Count Word Frequency in a Text
How Does Codeigniter Receive the Ajax Post Data in Controller
Redirect to New Page W/ Post Data (Php/Zend)
PHP Datetime::Createfromformat in 5.2
Shell_Exec() Timeout Management & Exec()
Xpath in Simplexml for Default Namespaces Without Needing Prefixes
Use of Undefined Constant Stdin - Assumed 'Stdin' in C:\Wamp\Www\Study\Sayhello.PHP on Line 5
Http Header for Downloading Microsoft Word and Excel Files
How to Check If User Has Already Liked the Facebook Page
PHP File_Get_Contents Ignoring Timeout
What Is the Rfc Compliant and Working Regular Expression to Check If a String Is a Valid Url
Twig Problem with PHP 7.4 in Write Variable