php与mysql数据库建立连接

时间:2015-08-31 12:15:37

标签: php

大家好我正在尝试连接MySQL数据库,但收到此错误:

  

警告:mysqli_connect():( HY000 / 1045):拒绝访问用户' root' @' localhost' (使用密码:是)错误:无法建立连接。访问被拒绝用户' root' @' localhost' (使用密码:是)。        这是我的代码:

 <?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());
   }
 ?>

2 个答案:

答案 0 :(得分:0)

正确的语法是:mysqli_connect("myhost","myuser","mypassw","mybd")

所以试试:

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

refer this

答案 1 :(得分:0)

基本上如果你是PHP的新手,那么你应该     1.首先启动Xamp / Wamp服务     2.密码的DB凭据应该是$ password =&#34;&#34;。