PDO laststatment-> fetchAll(PDO :: FETCH_COLUMN,$ column)会在每次调用时重新运行查询吗? [英] Will PDO laststatment->fetchAll(PDO::FETCH_COLUMN, $column) rerun the query each call?
问题描述
我正在执行一个获取两个字段的查询.
我需要将每个字段放入不同的数组中.
这会为每个调用重新运行查询,还是只是对结果集进行迭代?
I am doing a query which fetches two fields.
I need each of those fields into a different array.
Will this rerun the query for each call or just re iterate over the result set?
$a= Laststatment->fetchAll(PDO::FETCH_COLUMN,0);
$b= Laststatment->fetchAll(PDO::FETCH_COLUMN,1);
推荐答案
选项3:由于已获取所有内容,因此它根本不会在结果集上重复,并且第二次调用将返回一个空数组(至少,在这里).
Option 3: it will NOT reiterate over the resultset at all, as everything already has been fetched, and the second call will return an empty array (at least, here it does).
$a = array();
$b = array();
while($r = $laststatement->fetch(PDO::FETCH_NUM)){
$a[] = $r[0];
$b[] = $r[1];
}
也就是说,在MySQL中没有可滚动的游标,我没有尝试使用PDO :: CURSOR_SCROLL可能性的其他数据库.
That is: with MySQL there is no scrollable cursor, I have not attempted other database with a PDO::CURSOR_SCROLL possibility.
这篇关于PDO laststatment-> fetchAll(PDO :: FETCH_COLUMN,$ column)会在每次调用时重新运行查询吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!