title: Which is faster / more efficient - lots of little MySQL queries or one big PHP array?
body: <p>I have a PHP/MySQL based web application that has internationalization support by way of a MySQL table called <code>language_strings</code> with the <code>string_id</code>, <code>lang_id</code> and <code>lang_text</code> fields.</p>
  <p>I call the following function when I need to display a string in the selected language:</p>
  <pre class="lang-php prettyprint-override"><code>public function get_lang_string($string_id, $lang_id)
      {
          $db = new Database();
          $sql = sprintf('SELECT lang_string FROM language_strings WHERE lang_id IN (1, %s) AND string_id=%s ORDER BY lang_id DESC LIMIT 1', $db-&gt;escape($lang_id, 'int'), $db-&gt;escape($string_id, 'int'));
          $row = $db-&gt;query_first($sql);
  
          return $row['lang_string'];
      }
  </code></pre>
  <p>This works perfectly but I am concerned that there could be a lot of database queries going on. e.g. the main menu has 5 link texts, all of which call this function.</p>
  <p>Would it be faster to load the entire <code>language_strings</code> table results for the selected <code>lang_id</code> into a PHP array and then call that from the function? Potentially that would be a huge array with much of it redundant but clearly it would be one database query per page load instead of lots.</p>
  <p>Can anyone suggest another more efficient way of doing this?</p>