【发布时间】:2018-01-14 00:54:37
【问题描述】:
我在尝试下面的代码时收到以下错误:
错误:Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /volume1/web/index.php on line 4 Warning: mysqli::query(): Couldn't fetch mysqli in /volume1/web/index.php on line 7 Warning: main(): Couldn't fetch mysqli in /volume1/web/index.php on line 23
我正在使用的代码..
<?php
// Connect to the DB
$mysqli = NEW MySQLi("localhost","root","","dbproject");
//Query the DB
$resultSet = $mysqli->query("SELECT * FROM clients");
// Count the returned rows
if($resultSet->num_rows != 0) {
while($rows = $resultSet->fetch_assoc())
{
$id = $rows['id'];
$fname = $rows['firstname'];
$lname = $rows['lastname'];
$country = $rows['country'];
echo "<p>ID: " .$id. " <br /> Name: ".$fname." ".$lname. "<br /> Country: ".$country." </p>";
}
// Turn the results into an array
// Display the results
} else{
echo $mysqli->error;
}
?>
由于错误涉及第 4、7 和 23 行
第 4 行:
$mysqli = NEW MySQLi("localhost","root","","dbproject");
第 7 行:
$resultSet = $mysqli->query("SELECT * FROM clients");
第 23 行:
echo $mysqli->error;
有人可以帮我解决这个问题吗?非常感谢!
【问题讨论】: