PHP script: Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in

Viewed 4069

I use the following code to connect to the database on my webserver:

$conn = new mysqli("localhost", "username", "password", "database_name");

This connection works fine, I can use my website (which makes a lot of queries to the database) without a problem.

However I am facing a problem with a PHP script that loads about 8000 products from a product feed. At each product that I load I make a connection with the database (and I close this connection when a product is done loading). When I start this script up it usually (it somehow sometimes works) gives the following error (note: this error occurs directly at the start, it doesn't load any products):

Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in

I am aware that there are already many other topics with this same error, however I have not managed to resolve my issue. One of the things I have attempted is to replace 'localhost' with '127.0.0.1'. However this changes the error mentioned above to:

Warning: mysqli::mysqli(): (HY000/2002): Connection refused in

I hope someone has an idea why these errors occur I look forward for your input, thank you.

2 Answers

I was facing the exact same problem. just change the server name from

localhost

to

localhost:3306
Related