php – Getting connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known
php – Getting connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known
Thanks Prerak,
This is the answer, my database is on the same machine so I just needed to edit:
$servername = localhost
Now everything is working just fine.
The value youve specified for $servername
is not a host name but rather a URL, or resource name. The host name would be just www.url.com
.
Of course, as youve already discovered, localhost
is the correct host name if the client and server reside on the same box.
php – Getting connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known
For people coming from Google:
If you work with Docker, you might use the name of the database docker container here, like
$dbserver=mydockerbox-mysql;
if your docker-compose.yml
looks like this:
services:
mydockerbox-mysql:
image: mysql:5.7.26
container_name: mydockerbox-mysql
Related posts on php :
- php – what is the difference between site_url() and base_url()?
- php – regex match any whitespace
- php – How to get cookie value
- php – Difference between a normal ajax and long polling
- php – mysqli_real_escape_string – example for 100% safety
- php get URL of current file directory
- php – Invalid column count in CSV input on line 1 Error
- floating point – How to convert float value to integer in php?