I know this same warning has been asked many times here. But in all the queries I saw some mistake in the program because of which the user was not able to access the database.
But in my case I am accessing directly using the user which has access rights to the database, but even then this warning is coming
php_network_getaddresses: getaddrinfo failed: No such host is known
<?php
$conn_error = 'Could not connect.';
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db = 'a_database';
if(!mysqli_connect('mysql_host','mysql_user','mysql_pass','mysql_db')){
die($conn_error);
}
else{
echo 'connected';
}
It is giving the error message of not connected.
Although the users have the privilege to access the database.
You forgot to put the $
in (as variables)
if(!mysqli_connect('mysql_host','mysql_user','mysql_pass','mysql_db'))
those are being treated as strings.
$mysql_host = 'localhost';
. Therefore, replace that with; while removing the quotes.
Sidenote: If you intend on putting the $
inside single quotes, it won't work. Variables do not get parsed in single quotes, but in double quotes, however they're not required here. Consult "references" below.
if(!mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db))
and this die($conn_error);
(Could not connect.) doesn't help you.
This does:
Reference(s):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.