本文介绍了PDO MySQL fetchAll()是否在结果中使用了两倍的必要内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将->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.
推荐答案
是的.请参见手册:
使用可选的$fetch_style
参数来更改fetchAll()的行为方式.
Use the optional $fetch_style
parameter to change the way fetchAll() behaves.
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
这篇关于PDO MySQL fetchAll()是否在结果中使用了两倍的必要内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!