PDO MySQL fetchAll()是否在结果中使用了两倍的必要内存? [英] PDO MySQL fetchAll() using double the necessary memory in result?
问题描述
当我将->fetchAll()
与PDO一起使用时,当我执行print_r()
时,结果数组如下所示:
When I use ->fetchAll()
with PDO, the resulting array looks like this when I do a print_r()
:
Array
(
[0] => Array
(
[week] => 2006-03-05
[0] => 2006-03-05
[ath] => 112.89166667
[1] => 112.89166667
)
[1] => Array
(
[week] => 2006-03-12
[0] => 2006-03-12
[ath] => 260.04527778
[1] => 260.04527778
)
[2] => Array
(
[week] => 2006-03-19
[0] => 2006-03-19
[ath] => 219.23472222
[1] => 219.23472222
)
等,等等.
结果值是否两次存储在内存中?一个在数字数组索引下,例如0
和1
,另一个在其命名索引下,例如week
或ath
?
Are the resulting values stored twice in memory? One under a numerical array index like 0
and 1
, and the other under its named index, such as week
or ath
?
我主要只是好奇.我不认为这会真正影响我的程序.谢谢.
I am mainly just curious. I don't expect this to really impact my program significantly. Thanks.
推荐答案
结果值是否两次存储在内存中?
Are the resulting values stored twice in memory?
是的.请参见手册:
PDO :: FETCH_BOTH(默认值):返回一个在结果集中返回的同时由列名和0索引列号索引的数组
PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set
使用可选的$fetch_style
参数来更改fetchAll()的行为方式.
Use the optional $fetch_style
parameter to change the way fetchAll() behaves.
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
这篇关于PDO MySQL fetchAll()是否在结果中使用了两倍的必要内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!