MySQL Error - No such file or directory. even though I don't use localhost

My hostname is not localhost.

$hostname = "";
$username = "epiz_32278910";
$password = "NOPE";
$dbname = "epiz_32278910_distweb";
$db = new mysqli($hostname, $username, $password, $dbname);

But it still raise an error.

Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /home/vol16_1/ on line 99

How to fix it?

Welcome. What is on line 99 (Mark it please), and what code surrounds it?

Have you tried checking for connection errors?


Thanks for ur reply. I tried checking the connection error but I can’t because $db->connect_error cannot execute since $db = new sqli(...) caused an error.

Wait i mean i can check the error, wait

The error (2002) Can’t connect to … normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server.

Another thing to note: in the Distweb/index.php file, I see you’re defining the configuration in the global scope on line 88, but the mysqli call on line 102 is made within the signUp function.

But code within functions cannot access variables defined outside the function. So all the configuration variables cannot be used there.

You can import them using the global keyword (but that’s considered bad design), or by defining the configuration values as constants.

And you can use either the procedural style mysqli_connect or object-oriented style new mysqli. They work the same but are accessed a bit differently.


Okay thx but how can i know if i am using localhost? in hostname?

I connect mysql database in subdomain directory but it’s not working

The “No such file or directory” error is usually quite telling. Besides that, you’ll need to check your code.

Details please?

Some questions that would be helpful to answer:

  • Did you fix the issue I wrote about before?
  • What error message do you see right now?
  • What is the URL where this error message can be seen (and, if necessary, what steps must be taken on the page to see the error)?
  • In which file is the MySQL connection being set up?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.