将sql连接到php时出错

时间:2017-07-06 18:27:54

标签: php mysql

我写了以下代码行,它给了我错误:

<?php

$host = "Localhost";
$user = "usr_shiv";
$pass = "abcdsva234On0";
$dbName = "db_shiv";
$con = new mysqli($host,$user,$pass,$dbName);

if($con->connect_errno){
die("Error1 : ".$con->connect_error);
}

$sql = "INSERT INTO name (first, last)
VALUES ('John', 'Doe')";

if (mysqli_query($con, $sql)) {
echo "New record created successfully";
} 
else {
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}

$sql = "SELECT first, last FROM name";
$result = $con->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    echo "first: " . $row["first"]. " - last: " . $row["last"]."<br>";
}
} 
else {
echo "0 results";
}

$con->close();


?>

错误:

警告:mysqli :: __ construct():( HY000 / 1045):拒绝用户访问&#39; usr_shiv&#39; @&#39; localhost&#39; (使用密码:YES)在第11行的C:\ xampp \ htdocs \ mihir \ db.php中 错误1:拒绝用户访问&#39; usr_shiv&#39; @&#39; localhost&#39; (使用密码:是)

0 个答案:

没有答案