Beginner PHP Tutorial - 29 - die and exit Functions question

0 Ray LeDuc · April 24, 2015
Hi guys, I was following the tutorial and all was well until I refreshed the page and was not able to connect to the database the error i received was as follows:

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\series\die_and_exit_functions\index.php on line 13

Could not connect to database.

my code: 

Tried to insert my code not sure whats up. so will just type the few lines.

mysql_connect ('localhost' . 'root' , ' ' ) || die ('Could not connect to database.');
echo 'Connected';

 Your assistance is appreciated

Ray Leduc 

Post a Reply


Oldest  Newest  Rating
0 Peer Ligthart · April 30, 2015
Also, I'd recommend you using MySQLi since MySQL will not be supported by PHP in the future.

$conn = new mysqli('host','username','password','database');

For more information:
+1 Mohamad Mirohamadi · April 29, 2015
1. Check out if you installed MySQL separately you need to remove it , because XAMPP will install MySQL too.
2. go to http://localhost/security/index.php and set password for your MySQL(root user)
I wish this helps you.
best regards
0 Ray LeDuc · April 25, 2015
So I went to localhost/phpmyadmin page under users and of all the users including root have No password on them. so not sure. To be clear I'm running Xampp not a live hosted version.
0 Gilbert Diaz · April 25, 2015
It is a file, I don't remember the name of it where you setup if you are going to use password for the root access or not.  In the first line you have using password: YES. In your code you have the password parameter empty
mysql_connect ('localhost' . 'root' , 'password goes here ' ) || die ('Could not connect to database.');
echo 'Connected';

It is a .php file where you change that setting.
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.