与数据库的连接正常。 display_all()
是问题所在。它没有显示结果,因为它显示有人可以帮助确定问题所在的位置。我是一个很新的PHP,我刚刚花了几个小时,但不知道问题是什么。我试图显示数据库的结果。我想如果有人能够确定问题或事实在程序中的确切位置。
<?php
class connect_dbase{
public $mysqli;
public function connection($host="localhost",$user="root",$password="london",$db_name="users")
{
$this->mysqli=new mysqli($host,$user,$password,$db_name);
if ($this->mysqli->connect_error) {
die('Connect Error: ' . $this->mysqli->connect_error);
}
else
{
echo " Database connection successful";
}
}
public function display_all($id)
{
if($stmt = $this->mysqli->prepare("SELECT * FROM user WHERE id =?"))
{
/* bind parameters for markers */
$stmt->bind_param('i',$id);
/* execute query */
$stmt->execute();
if($stmt->num_row() >0)
{
echo 'Total results: ' . $resultrol->num_rows;
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
// do something with $row
echo $row['name'];
}
}
else
{
echo "no result found";
}
}
else
{
echo "cant prepare result";
}
}
}
$connect_dbase=new connect_dbase();
$connect_dbase->connection();
$connect_dbase->display_all(2);
?>
答案 0 :(得分:1)
echo 'Total results: ' . $resultrol->num_rows;
$result = $stmt->get_result();
不应该$resultrol
未定义吗?