PHP Zend - 执行以获取行集和记录总数
我遇到一些问题,我想执行SQL语句并获取记录总数+所有记录。
$strSQL = "SELECT * FROM table WHERE ProjectID = 1 ";
$stmt = $db->query($strSQL);
$total = count($stmt->fetchAll());
while ($row = $stmt->fetch()){
..No More Record Shown here..
}
但是在我执行 fetchAll 后 while 循环中没有更多记录,我相信我需要返回到第一行或其他内容,有人知道如何解决这个问题吗?
I encounter some problem where i want to execute a SQL statement and get the total number of records + all the records.
$strSQL = "SELECT * FROM table WHERE ProjectID = 1 ";
$stmt = $db->query($strSQL);
$total = count($stmt->fetchAll());
while ($row = $stmt->fetch()){
..No More Record Shown here..
}
but there is no more record in the while loop after i execute fetchAll, i believe I need to get back to the first row or something, anyone know how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经使用
fetchAll()
获取了所有记录。因此,当您调用fetch()
时,就没有更多记录可供读取。尝试将 fetchAll() 的返回值存储在变量中并对其进行迭代。像这样的东西:You've already fetched all the records with
fetchAll()
. So when you callfetch()
, there are no more records to read. Try storing the return value offetchAll()
in a variable and iterating through that. Something like this: