I have a PHP / MySQL based web application that supports multiple language support using the MySQL table "language_strings" with fields string_id, lang_id, lang_text. Then I call the following function when I need to display a string in the selected language ...
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->escape($lang_id, "int"), $db->escape($string_id,"int")); $row=$db->query_first($sql); return $row['lang_string']; }
This works fine, but I am concerned that there may be many database queries. for example, in the main menu there are 5 link texts, all of which call this function.
Would it be faster to load all the results of the language_strings table for the selected lang_id into a PHP array and then call it from a function? This would potentially be a huge array with mostly redundant, but obviously it would be a single database query for pageload instead of lots.
Can someone suggest another more efficient way to do this?
performance arrays php mysql
Pandy legend
source share