开发者

PDO MySQL fetchAll() using double the necessary memory in result?

开发者 https://www.devze.com 2023-02-13 11:42 出处:网络
When I use ->fetchAll() with PDO, the resulting array looks like this when I do a print_r(): Array (

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
        )

etc., etc.

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?

Yes. See the manual:

PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set

Use the optional $fetch_style parameter to change the way fetchAll() behaves.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号