mysqli_connect throws exception "No such file or directory"

26 Views Asked by At

I have a MySQL data base, and mysqld is running.

In a php file i have:

<?php  

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // Set MySQLi to throw exceptions 

$g_dbconn = 0;
$g_hostname = "localhost";
$g_dbname   = "test_db";
$g_user     = "test_user";
$g_pw       = "test_pw";

try { 
    $g_dbconn = mysqli_connect($g_hostname, $g_user, $g_pw, $g_dbname);
    println("Success!");
} catch (mysqli_sql_exception $e) {
    die('Could not connect using: '. $g_hostname.' ' . $g_dbname.' '.  $g_user.' '. $g_pw   . ': Exception: ' . $e->getMessage().'<br/>');
}

?>

When i run this code in the browser, the exception gets thrown and i get

Could not connect using: localhost test_db test_user test_pw: Exception: No such file or directory

i.e. the exception has been thrown, but there is no further explanation.

I get the same message if i call this php file from the console:

php test_mysql.php 

The connection parameters are in order - using them i can log in to mysql on the console without any problems.

What could cause this problem? How can i find out what file or directory does not exist?

0

There are 0 best solutions below