mysqli_fetch_array() or mysqli_fetch_all()?

后端 未结 2 896
花落未央
花落未央 2021-01-19 10:59

I see comparisons between mysqli_fetch_array() and mysqli_fetch_all() that say that with mysqli_fetch_all() it will take more memory a

2条回答
  •  独厮守ぢ
    2021-01-19 11:34

    From PHP's page on mysql_fetch_all():

    I tested using fetch_all versus while / fetch_array and:

    fetch_all uses less memory (but not for so much).

    In my case (test1 and test2): 147008,262848 bytes (fetch_all) versus 147112,262888 bytes (fetch_array & while).

    So, about the memory, in both cases are the same.

    However, about the performance:

    My test takes :350ms (worst case) using fetch_all, while it takes 464ms (worst case) using fetch_array, or about 35% worst using fetch_array and a while cycle.

    So, using fetch_all, for a normal code that returns a moderate amount of information is:

    a. cleaner (a single line of code)
    b. uses less memory (about 0.01% less)
    c. faster.

    php 5.6 32bits, windows 8.1 64bits

提交回复
热议问题