-3

Hello everyone am trying to connect to MySQL database but getting this error:

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) Error: Could not establish connection.Access denied for user 'root'@'localhost' (using password: YES). Here is my code:

 <?php        
    $host = "localhost";
    $db   = "resumedb";
    $username = "root";
    $password = "sa";        

$phpConnect = mysqli_connect($host, $username, $db, $password);
    //checking the if connection.    
 if($phpConnect === false)
   {
      die("Error: Could not establish connection.".mysqli_connect_error());
   }
 ?>
Klint
  • 1
  • 3
  • 2
    possible duplicate of [Warning: mysqli\_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)](http://stackoverflow.com/questions/25174183/warning-mysqli-connect-hy000-1045-access-denied-for-user-usernameloca) – Marcelo Camargo Aug 31 '15 at 12:17
  • Please I appreciate any help from any one. Thanks in advance. – Klint Aug 31 '15 at 12:17
  • What exactly was unclear about the error message? – David Aug 31 '15 at 12:18
  • Error It self giving the Answer that "User Root is not authorized to access the database you are trying to connect." – Harshal Aug 31 '15 at 12:18
  • Make sure the db credentials are correct and working. – Jenis Patel Aug 31 '15 at 12:24
  • I can't tell you how bad this would be on a production database, please create a user with access only to this db. You could give your user access from any location. GRANT ALL PRIVILEGES ON `resumedb` . * TO 'dbuser'@'%' WITH GRANT OPTION ; – Phil Lawlor Aug 31 '15 at 12:34
  • Thanks to every one out there for your contributions the connection has just been established after granting access in the config file. – Klint Aug 31 '15 at 13:44

2 Answers2

0

The right syntax is:mysqli_connect("myhost","myuser","mypassw","mybd")

so try:

$phpConnect = mysqli_connect($host, $username, $password, $db);

refer this

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
0

Basically If you are the newbee in PHP so you should
1.first start the Xamp/Wamp service.
2.else db credentials for password should be $password = "".