0

I'm presently reading the book "Head First jQuery" and came across this bit of code :

mysql_connect('127.0.0.1', 'runner_db_user', 'runner_db_password')
    OR die( 'Could not connect to database.');
mysql_select_db('race_info');

But since mysql_connect is deprecated, I decided to use mysqli_connect via

mysqli_connect('127.0.0.1','runner_db_user','runner_db_password','race_info')
    or die('Error connecting to Database');

However I get an error saying

Warning: mysqli_connect(): (HY000/1044): Access denied for user 'runner_db_user'@'localhost' to database 'race_info' in E:\wamp\www\Z_jquery\ch9\service.php on line 2

I created the user 'runner_db_user'@'localhost' and a database for it to use, using:

create database race_info;

CREATE USER 'runner_db_user'@'localhost' IDENTIFIED BY 'runner_db_password';
GRANT SELECT,INSERT,UPDATE,DELETE ON race_info.* TO 'runner_db_user'@'localhost';

I've confirmed using phpMyAdmin that both the user exists and it has the privileges granted by the above commands. Why then am I not able to connect to the database?

NOTE : I also was able to manually connect to the database using said login credentials via command line:

mysql -u runner_db_user -p

Why am I then unable to connect to the database via mysqli_connect()? Are there any further permission that I need to provide to the user to connect successfully?

EDIT : This is the present condition of my users. Are there any anonymous users that may cause this problem, according to the best answer here? If so, how do I delete these users?

User Previledges

Community
  • 1
  • 1
Somenath Sinha
  • 1,174
  • 3
  • 16
  • 35

0 Answers0