如何在PHP中一次从MySQL表中获取多行?
假设我的查询总共返回5行,并且我指定块大小为2,该函数必须连续返回一个包含2+2+1行的对象/数组。
附注:我知道我可以手动迭代所有的结果,然后自己做同样的实现,但我正在寻找一些内置的函数,它能以一种干净和优化的方式做到这一点。
发布于 2012-11-29 01:12:23
您要查找的函数不存在。你自己写吧。
发布于 2012-11-29 01:15:50
如果您尚未使用PDO对象,请考虑使用它。这样,您就可以使用fetchAll函数了。
<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
?>获取结果集中的所有剩余行:
Array
(
[0] => Array
(
[NAME] => pear
[0] => pear
[COLOUR] => green
[1] => green
)
[1] => Array
(
[NAME] => watermelon
[0] => watermelon
[COLOUR] => pink
[1] => pink
)
)https://stackoverflow.com/questions/13610651
复制相似问题