Which is faster / more efficient - lots of little MySQL queries or one big PHP array?

前端 未结 6 1019
离开以前
离开以前 2021-02-06 01:55

I have a PHP/MySQL based web application that has internationalization support by way of a MySQL table called language_strings with the string_id,

6条回答
  •  佛祖请我去吃肉
    2021-02-06 02:26

    I'm with Fluffeh on this: look into other options at your disposal (joins, subqueries, make sure your indexes reflect the relativity of the data -but don't over index and test). Most likely you'll end up with an array at some point, so here's a little performance tip, contrary to what you might expect, stuff like

    $all = $stmt->fetchAll(PDO::FETCH_ASSOC);
    

    is less memory efficient compared too:

    $all = array();//or $all = []; in php 5.4
    while($row = $stmt->fetch(PDO::FETCH_ASSOC);
    {
        $all[] = $row['lang_string '];
    }
    

    What's more: you can check for redundant data while fetching the data.

提交回复
热议问题