1

I am trying to connect php file with MySQl Server database in MacBook Air using Terminal. It shows me

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

I have seen many solution in Stack Overflow but I doesn't give the solution. I have tried by giving first parameter as both localhost and 127.0.0.1 but it gives me pic2 given below.

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

My PHP code is below:

    <?php
$connection = mysqli_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', '1234');
if (!$connection){
    die("Database Connection Failed" );
}
$select_db = mysqli_select_db($connection, '');
if (!$select_db){
    die("Database Selection Failed" . mysqli_error($connection));
}
    ?>
halfer
  • 19,824
  • 17
  • 99
  • 186
Abinav
  • 7
  • 1
  • 4
  • Looks like permission issues. – M A Dec 06 '18 at 03:52
  • `dtruss -f -t open php ....`. See what its looking for. Or are you using PHP7 and [mysqli_connect](https://secure.php.net/manual/en/function.mysql-connect.php) no longer exists? – danblack Dec 06 '18 at 03:56
  • Possible duplicate of [Error #2002 Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)](https://stackoverflow.com/questions/11105796/error-2002-cant-connect-to-local-mysql-server-through-socket-applications-ma) – Will B. Dec 06 '18 at 04:06
  • 1
    Sounds like the mysql service is not running. – Will B. Dec 06 '18 at 04:07
  • No it is running at back...Still now I can't solve the problem – Abinav Feb 12 '19 at 06:48

0 Answers0