Hello, When I am trying to connect to mysql database from php script I am getting following error. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in D:\tools\Apache2\htdocs\saz\admin\index.php on line 27 /* PHP code start*/ //Set database connection $server = mysql_connect($host, $username, $password) or die("Can't find the Database Server"); // Select the database now: $connection = mysql_select_db($database, $server) or die("Invalid Database schema"); $sql = "SELECT * FROM users WHERE userID = '$userID' AND password = '$password'"; $results = mysql_query($sql); if ($user = mysql_fetch_array($results)) { echo $user['name']; } mysql_close($server); /* PHP code ended */ Code (markup): All the required information provided to database server are correct. I using following environment: apache 2.0.53, mysql 4.1.22-community-nt, PHP 5.1.1 Please guide me how to fix the issue. Thank you,
Try connecting to mysql from command line. <Path>\mysql.exe -u root -p <password> If that works, nothing wrong with setup, it could be something in the code. If that does not work, login to mysql and run this command: SET PASSWORD FOR 'root'@'host_name' = PASSWORD('eagle'); where eagle is the password. Details here: http://dev.mysql.com/doc/refman/5.0/en/access-denied.html Try the command line version again and make sure it works.
I just found out that I am using two same variables on the page, thats causing the problem. any ways thanks for replying.