mysql数据库和php之间的连接错误

时间:2019-05-12 19:02:08

标签: php mysql

当我尝试连接到数据库时,似乎出现了某种错误,我检查以确保凭据正确无误,尝试从另一个文件导入它,但这也无济于事。错误出现在                $ conn =新的mysqli($ dbhost,$ dbuser,$ dbpassword,$ db)或die(“连接失败:%s \ n”。$ conn-> error);  有什么建议吗?

        // creating the connection to database
          $dbhost="localhost";
          $dbuser = "Mydatabase";
          $dbpassword="123";
          $db="userweight";

          // connecting to the database 
          $conn = new mysqli($dbhost,$dbuser,$dbpassword,$db) or die("connection failed: %s\n". $conn->error);

          // creating the table 
          $table="CREATE TABLE Users(
            id INT(0) PRIMARY KEY,
            FirstName VARCHAR(50) NOT NULL,
            LastName VARCHAR(50) NOT NULL,
            Password  VARCHAR() NOT NULL,
            EMAIL   VARCHAR ()  NOT NULL
          )";

         if($conn->query($table) === TRUE){
           echo"Table created successfully";
          }else{
            echo "Error creating table: " . $conn->error;
          }
        $conn->close();
          ?>

编辑1

我得到的错误:

  

警告:mysqli :: __ construct():(HY000 / 1044):拒绝用户访问   将'Mydatabase'@'localhost'转换为数据库'userweight'中的   C:\ xampp \ htdocs \ Weight-tracker \ signup.php,第64行


编辑2

没有授予Mydatabase@localhost的特权,这就是问题所在。授予特权解决了该问题!

0 个答案:

没有答案