gpt4 book ai didi

php - PDO MySQL fetchAll() 结果使用双倍的必要内存?

转载 作者:IT王子 更新时间:2023-10-29 00:12:46 26 4
gpt4 key购买 nike

当我将 ->fetchAll() 与 PDO 一起使用时,当我执行 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
)

等等等等

结果值是否在内存中存储了两次?一个在数字数组索引下,如 01,另一个在其命名索引下,如 weekath?

我主要是好奇。我不认为这会对我的计划产生重大影响。谢谢。

最佳答案

Are the resulting values stored twice in memory?

是的。查看manual :

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() 的行为方式。

$result = $sth->fetchAll(PDO::FETCH_ASSOC);

关于php - PDO MySQL fetchAll() 结果使用双倍的必要内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5130212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com