当我尝试下面的代码时,我得到了以下错误:
错误: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;有没有人能帮我一下?非常感谢!
发布于 2018-01-14 09:02:38
解决方案:
我将第4行代码从:
$mysqli = NEW MySQLi("localhost","root","","dbproject");至
$mysqli = NEW MySQLi("localhost:3307","root","","dbproject");添加端口以某种方式修复了它。
发布于 2018-01-14 09:06:59
我刚刚在我的服务器上试过了,我看不出有什么问题。只需确保登录详细信息与数据库和表名一样正确即可。
这是我刚刚在我的服务器上测试的脚本。我添加了一个连接测试,并更改了数据库和表名:
<?php
// Connect to the DB
$mysqli = NEW MySQLi("localhost","root","","test");
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
//Query the DB
$resultSet = $mysqli->query("SELECT * FROM testing");
// Count the returned rows
if($resultSet->num_rows != 0) {
while($rows = $resultSet->fetch_assoc())
{
$id = $rows['ID'];
echo "<p>ID: " .$id. " </p>";
}
// Turn the results into an array
// Display the results
} else{
echo $mysqli->error;
}
?>https://stackoverflow.com/questions/48245769
复制相似问题