I need help bad...I got this error trying to display a database using php:
mysqli_connect(): (HY000/2002): Can't connect to local MySQL server
through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2) in
/Applications/MAMP/htdocs/databases.php on line 7 Database connection
failed: Can't connect to local MySQL server through socket
'/Applications/MAMP/tmp/mysql/mysql.sock' (2) (2002)
I've been trying to fix it for days, reading through this forum from people with the same issues, and applying the fixes (like this one http://tinyurl.com/q4cpxzj) with absolutely no luck.
Here's some steps I've tried: Going into php.ini file and changing the socket to /tmp/mysql.sock (I also tried changing it to /Applications/MAMP/tmp/mysql/mysql.sock to see what happens, no good).
Tried doing the same to /etc/my.cnf file. No good.
Tried a bunch of other things I can't even remember anymore.
Also, I'm using Mac 10.10.2 and I have MAMP installed. According to MAMP, only Apache is working (green light by Apache and nothing on MySQL) but I've downloaded MySQL and according to System Pref it is running, although it won't let me stop MySQL server for some reason (when I click stop it would stop then restart again on its own).
Please help...
If it matters, here's the php:
// 1. Create a database connection
$dbhost = "localhost";
$dbuser = "widget_cms";
$dbpass = "*********";
$dbname = "widget_corp";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
// Test if connection succeeded
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
"http://www.w3.org/TR/html4/loose.dtd">
Databases
// 5. Close database connection
mysqli_close($connection);
?>
No comments:
Post a Comment