PDOException: SQLSTATE[HY000] [2002] No such file or directory
When I connect using mysqli in php code its fine, but pdo code is causing an error, all the settings are the same so it doesnt look like a settings issue.
Is it something to do with sockets?
Code works fine on my local environment.
PDOException: SQLSTATE[HY000] [2002] No such file or directory in /home/vol1_6/epizy.com/epiz_21753785/htdocs/harms_add.php:62 Stack trace: #0 /home/vol1_6/epizy.com/epiz_21753785/htdocs/harms_add.php(62): PDO->__construct(‘mysql:host=;dbn…’, NULL, NULL) #1 {main}
Make sure you are using your hosting account password.
pwd is working with mysqli code - tested on a separate page
Make sure you are using the right database hostname (not localhost).
host is working with mysqli code - not mysql host - tested on a separate page
Make sure you are using the right database name and username
db and username work with mysqli code - tested on a separate page
also tried setting php version…
PHP Version 7.1.12on my dev - PHP Version 7.0.19 on here
PDOException: SQLSTATE[HY000] [2002] No such file or directory in /home/vol1_6/epizy.com/epiz_21753785/htdocs/harms_add.php:62 Stack trace: #0 /home/vol1_6/epizy.com/epiz_21753785/htdocs/harms_add.php(62): PDO->__construct(‘mysql:host=;dbn…’, NULL, NULL) #1 {main}
Make sure you are using your hosting account password.
pwd is working with mysqli code - tested on a separate page
Make sure you are using the right database hostname (not localhost).
host is working with mysqli code - not mysql host - tested on a separate page
Make sure you are using the right database name and username
db and username work with mysqli code - tested on a separate page
also tried setting php version…
PHP Version 7.1.12on my dev - PHP Version 7.0.19 on here
Like the article linked to says: the problem is that you’re not using the right database hostname.
In the error message, it looks like the host= section of your PDO connection string is empty. This would mean PDO falls back to the default host, which is localhost which doesn’t work on InfinityFree. If you set the host= part of the string to your actual database hostname, it should work.
On your local machine, you can go without explicitly setting the hostname and using the default localhost. But that’s because your MySQL database server and your PHP server are on your own computer, so localhost is where PHP can find your database.
On InfinityFree, the database servers are on separate servers from the websites themselves (database servers are faster), so using localhost from PHP will not point you to the database.
The issue is not the settings as they work on a test page using mysqli code on your servers.
I managed to get it working by taking the settings variables out of an include file into the page itself.
The question is why would putting the settings in an include file not work and what can I do to avoid having the settings in every page that has a db query?