$db = new MySQLi("localhost","root","","data");
if(!$db->connect_error){
echo "数据库连接成功"; //浏览器 返回 据库连接成功
$rows = $db->query("SELECT * FROM sy"); //select语句在sql里正确执行,显示sy表里内容
echo '<table border="1"><tr><td>姓名</td><td>工号</td></tr>';
while($row = $rows->fetch_assoc()){
echo '<tr><td>'.$row['姓名'].'</td>';
echo '<td>'.$row['工号'].'</td></tr>';
}
最后出现:错误 Call to a member function fetch_assoc() on a non-object
if(!$db->connect_error){
echo "数据库连接成功"; //浏览器 返回 据库连接成功
$rows = $db->query("SELECT * FROM sy"); //select语句在sql里正确执行,显示sy表里内容
echo '<table border="1"><tr><td>姓名</td><td>工号</td></tr>';
while($row = $rows->fetch_assoc()){
echo '<tr><td>'.$row['姓名'].'</td>';
echo '<td>'.$row['工号'].'</td></tr>';
}
最后出现:错误 Call to a member function fetch_assoc() on a non-object