我有一个包含 3 行的表。我正在尝试遍历所有行,但没有得到正确数量的行。
我的代码如下:
$result1_prepare = $DB->prepare("SELECT * FROM table");
$result1_prepare->execute();
$num = $result1_prepare->fetchColumn();
$result1 = $result1_prepare->fetchAll();
echo $num; //OUTPUT 3
echo count($result1); //OUTPUT 2
if($num > 0){
foreach ($result1 as $x => $row) {
//LOOPING only 2 times, 1 row is not showing
}
}
fetchAll() 函数只返回 2 行。怎么会?