我正在尝试使用php代码连接到mysql数据库,但是它给了我这个错误:警告:mysqli_connect():(HY000 / 1044):拒绝用户'@'localhost'访问C中的数据库'test1' :第8行的\ xampp \ htdocs \ imobiliare \ server.php
警告:mysqli_query()期望参数1为mysqli,第11行的C:\ xampp \ htdocs \ imobiliare \ server.php中给出的布尔值
警告:mysqli_num_rows()期望参数1为mysqli_result,第13行的C:\ xampp \ htdocs \ imobiliare \ server.php中给出的值为空
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "test1";
$conn = mysqli_connect($servername, $username, $password, $dbname);
$sql = "SELECT id, camere, zona, pret FROM apartamente";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. "Camere: " . $row["camere"]. "Zona:" . $row["zona"]. "Pret: " . $row["pret"]."<br>";
}
}
?>
我想回应结果
答案 0 :(得分:0)
您需要通过在MySQL提示符下运行命令来授予对数据库test1的访问权限
mysql>将所有特权授予test1。*至'username'@'localhost';