请告诉我,为什么这段代码错了?
function myres () {
$db = new mysqli("localhost","userrr","pass","mvc");
$res = $db->query("SELECT * FROM news ");
return $res;
}
while ($row = myres()->fetch_row()) {
echo $row[0];
}
P.S。 这段代码正在运行:
$db = new mysqli("localhost","userrr","pass","mvc");
$res = $db->query("SELECT * FROM news ");
while ($row = $res->fetch_row()) {
echo $row[0];
}
答案 0 :(得分:2)
我每次都打电话给myres()
,我想:
while ($row = myres()->fetch_row()) {
echo $row[0];
}
所以每次$row
包含结果的第一行,它都不会停止。我认为它会正常工作:
$res = myres();
while ($row = $res->fetch_row()) {
echo $row[0];
}