SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
Check your DB_HOST
on your .env
file
DB_HOST=http://localhost/
--> DB_HOST=localhost
Result:
I can migrate peacefully now.
php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
SQLSTATE[HY000][2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
Your quotes are all messed up.
$db = new PDO('mysql:host='.DBHOST.';port=8889;dbname='.DBNAME, DBUSER, DBPASS);
getaddrinfo for mysql failed: nodename nor servname provided
The hostname 'mysql' only works if you run it in a docker-compose or when the container is linked other ways or if you specify that in your /etc/hosts file. I guess the issue is that you need to run that artisan command inside that php container (instead of running it from the host itself) with docker exec something like this:
docker exec -it <php-containers-name> php artisan migrate
The other way is to expose the db containers port to the host so you can access it with 0.0.0.0:3306.
Using the docker-compose instead of pure docker to relay to the right containers then. What is the output of this command?
docker-compose exec -w="/var/www/html" php php artisan migrate
(It runs a 'php artisan migrate' inside the php container using /var/www/html as a working directory)
php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not knownfailed?
You might wanna switch your quote types around the connection variable; they aren't the exact same (even though they are similar), which could cause PHP to read the strings differently.
Try this:
$con=mysqli_connect("127.0.0.1","pks","sonisoni123","GDRS");
Echo mysqli_connect_error();
if($con)
{
echo "success";
}
else
{
echo "failed";
}
?>
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
I'm pretty sure it's because of the host's line! It should be
'host' => env('DB_HOST', 'localhost'),
OR
'host' => env('DB_HOST', '127.0.0.1'),
This part of the line php artisan make:migration create_users_table
is a Laravel command! You're supposed to do it in the command line (the terminal)!
Related Topics
How to Search Array for Multiple Values in PHP
Why Is My Number Value Changing Using Number_Format()
Fatal Error: Call to Undefined Function Openssl_Random_Pseudo_Bytes()
How to Remove <Br /> Tags and More from a String
Official End of Support for PHP4
PHP Get Name of Current Directory
Best Place for Validation in Model/View/Controller Model
Loop Through All Months in a Date Range
Using Named Parameters with Pdo for Like
How to Create Clean Url Using .Htaccess
How to Download a File Using Curl in PHP
Detect If Cookies Are Enabled in PHP
Override External Product Url to "Add to Cart" Product Button
Why Does PHP 7.4 on Windows Aborts All Command Line Actions That Require User Input