I'm trying to connect to a MySQL database through a php script. I have tried everything, but always end up with: "Connection failed: Access denied for user 'user'@'localhost' (using password: YES)"
I can connect to MySQL in the command line:
mysql -u user -p -h localhost
This is an example of the php script:
<?php
$DB_HOST = "localhost";
$DB_USER = "user";
$DB_PASS = "pass";
$DB_NAME = "dbname";
// Create connection
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
?>
These are the privileges set in the DB for the user:
Localhost:
GRANT USAGE ON *.* TO 'user'@'localhost' IDENTIFIED BY PASSWORD '*<numbers>'
GRANT ALL PRIVILEGES ON `dbName`.* TO 'user'@'localhost'
'%':
GRANT USAGE ON *.* TO 'user'@'%' IDENTIFIED BY PASSWORD '*<numbers>'
GRANT ALL PRIVILEGES ON `dbName`.* TO 'user'@'%'
I am running MAMP on my system.
Is there something else I'm missing with the privileges?