PHP PHP_Network_Getaddresses: Getaddrinfo Failed: No Such Host Is Known

PHP php_network_getaddresses: getaddrinfo failed: No such host is known

IMO it's the different way to resolve a name from the OS and PHP.

Try:

echo gethostbyname("host.name.tld");

and

var_export (dns_get_record ( "host.name.tld") );

or

$dns=array("8.8.8.8","8.8.4.4");
var_export (dns_get_record ( "host.name.tld" , DNS_ALL , $dns ));

You should found some DNS/resolver error.

getaddrinfo failed: No such host is known

replace server name from

$servername = "http://localhost:8080";

to

$servername = "localhost";

SQLSTATE[HY000] [2002]php_network_getaddresses: getaddrinfo failed: No such host is known

DB_HOST should be IP Address only

Change

DB_HOST=http://45.77.34.158/phpmyadmin

to

DB_HOST=45.77.34.158

if that doesn't work then run this command this will help you to clear cached config

php artisan cache:clear

php_network_getaddresses: getaddrinfo failed: No such host is known

Your connect statement

mysqli_connect('$host','$username','$password','$db');

needs to be changed to

mysqli_connect($host,$username,$password,$db);

Because you used '$host' it is literally passed $host as a string into the function, if you had of used "$host" you would have been ok, but the quotes are ultimatly redundant in this instance.

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. Error in laravel 8

The error PDO::__construct("mysql:host=mysql;port=3306;dbname=crudtwo", "root", "", []) shows that you have a wrong entry in .env file

Change the DB_HOST in .env file as

//Change
DB_HOST=mysql

//To
DB_HOST=127.0.0.1

Warning : php_network_getaddresses: getaddrinfo failed: No such host is known

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.

  • You're trying to connect to a host called "mysql_host", which is why it's not finding the intended "localhost" server address, as per $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:

  • http://php.net/manual/en/mysqli.error.php

Reference(s):

  • https://php.net/language.types.string
  • http://php.net/manual/en/language.variables.basics.php


Related Topics



Leave a reply



Submit