I’m getting the following error when I try to open up a connection with MySQL running on my MACBOOK:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/Eugene/Sites/website/includes/database.php on line 15 Warning: mysql_connect(): No such file or directory in /Users/Eugene/Sites/website/includes/database.php on line 15 Notice: Undefined variable: connection in /Users/Evgeny/Sites/website/includes/database.php on line 16 Database connection failed: No such file or directory
My constants are:
defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
defined('DB_USER') ? null : define("DB_USER", "eugene");
defined('DB_PASS') ? null : define("DB_PASS", "password"); // no comments please :)
defined('DB_NAME') ? null : define("DB_NAME", "maindb");
The way I try to connect is:
$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if(!$connection) // if no connection - die
{
die("Database connection failed: " . mysql_error());
}
else // if there is a connection, then go and select a database
{
$db_select = mysql_select_db(DB_NAME, $connection);
if(!$db_select) // if no database selected - die
{
die("Database selection failed: " . mysql_error());
}
}
Please help,
Thanks in advance.
First problem is that mysqld is not using the same socket path as the client. Try accessing via 127.0.0.1 then run ‘show variables’ to find it where it has put the socket – update your PHP config appropriately.
But you put the connection in ‘$this->connection’ not ‘$connection’