I am trying to test my account system on my laravel project, I have input the correct mysql details such as the correct host, db, password and user however any attempt i make to connect to the database and run a query, it just returns
"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known."
The database is on my school's server which i have full access to my account, so i am able to read and write to it, I have already connected to it before to run the migrations which created the "users" and "posts" tables and they were successful. I am unsure what is going wrong as if it had already connected then why would it return "No such host is known".
@MUSA11971 - Thanks for the quick reply, unfortunately, I have tried both of these and still no success, I have tried adding quotation marks around the password, the username, and the host but still no luck.
I just don't understand that I was able to connect with the same details to migrate the database, but not create data
I have just noticed, I have tried to change the .env multiple times, trying it on my local database server, tried to migrate my tables but it was telling me that I was still trying to connect to the external server, not the local database.
I have tried to clear the cache and config, turned off my computer and tried doing multiple things, but still no luck, i don't think it is using my .env file as i have also tried resetting my app_key and nothing changes within the .env but no luck. Not sure what is going on as i can't get anything to work. If anyone knows why the .env file isn't working as expected please explain.
@JLRDW - I am able to connect and edit the tables using the exact details and there is only 1 instance of MySQL running so I am connecting to the correct one.
@SNAPEY - I have changed this, however still no luck. If you read my reply above, I have explained that for some reason, my app isn't looking at the .env and it is continuing to look at the cached .env file. However, I have cleared the cache to reset this but it continues to use a cached version of .env from somewhere
have you try to ping the exact host and telnet the exact host with the port??
And do check the error log for more details sometime it may help. telescope is one of the great debugging tool that you can try.
Also had this issue -- after doing a few online tuts and various exercise - in one of the tuts they suggested changing the sql ip to localhost -- all worked well except when trying to register a user... changed it back, cleared cache and all went back to normal.
The solution is simple really. Just comment out the DB_HOST section in your .env file. It's throwing this error because it doesn't recognize the host that you have declared as the DB_HOST.