0

I'm using OS X El Capitan. Mysql is running and I am able to add tables using the mysql command-line tool. When I try to connect to the database from my PHP file I get a 1045 error. Below is the code:

$dbc = mysqli_connect('127.0.0.1', 'root', '*****', 'aliendatabase')
// or die('Error connecting to MySQL server. ');
or die("Debugging errno: " . mysqli_connect_errno() );

$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .
"how_many, alien_description, what_they_did, fang_spotted, other, email) " .
"VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " .
"'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";

$result = mysqli_query($dbc, $query)
or die('Error querying database.');

mysqli_close($dbc);

I have set the grant options as below:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*477A2FE5488EA451D53F4BFE898AA4D4F61B68EF' WITH GRANT OPTION GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION

I can't work out why this isn't working and I've tried starting the mysql process with both mysql.server start and mysqld. Obviously, the asterisks in the connection arguments are representing my password. Does anybody know what I'm missing?

Andrew Trigg
  • 49
  • 1
  • 7

1 Answers1

0

You're granting privileges on localhost and then connecting to 127.0.0.1

Try changing 127.0.0.1 to localhost in your connection:

$dbc = mysqli_connect('localhost', 'root', '*****', 'aliendatabase')

Or at least ensure root@127.0.0.1 has also been granted appropriate permissions.

mferly
  • 1,586
  • 1
  • 11
  • 18
  • Thanks for the response. I did in fact grant the permissions as you said, but when I show grants the 127.0.0.1 has become `localhost`. Furthermore, when I use `localhost` as an argument in the `mysqli_connect()` function, I get a different error because it is not mapping `localhost` to `127.0.0.1`. This is a separate problem for me to deal with later. – Andrew Trigg Apr 10 '16 at 18:24