作者:你的念头_780 | 来源:互联网 | 2023-09-02 04:30
followingproblem:Iwanttobuildamysqlbasedlanguagesystem.下面的问题:我想构建一个基于mysql的语言系统。Todec
following problem: I want to build a mysql based language system.
下面的问题:我想构建一个基于mysql的语言系统。
To decrease loading time and increase performance I thought it would be the best, to first fetch all Language phrases into an array (which happens with mysqli fetch array). Then, if a language term is required, calling a function with the array as global variable.
为了减少加载时间并提高性能,我认为最好是首先将所有语言短语提取到一个数组中(mysqli fetch array就是这样的)。然后,如果需要一个语言术语,则调用具有数组作为全局变量的函数。
My function for the array:
我的数组函数:
$sql = $db->query('SELECT * FROM lang_phrases WHERE phraseLanguageId = 1');
$phrases = array();
while($row = $sql->fetch_array()) {
$phrases[] = $row;
}
Now I've got this array:
现在我有了这个数组:
array(2) {
[0]=> array(8) {
[0]=> string(1) "1"
["phraseId"]=> string(1) "1"
[1]=> string(1) "1"
["phraseLanguageId"]=> string(1) "1"
[2]=> string(4) "HOME"
["phraseKey"]=> string(4) "HOME"
[3]=> string(10) "Homepage"
["phraseContent"]=> string(10) "Homepage"
}
[1]=> array(8) {
[0]=> string(1) "2"
["phraseId"]=> string(1) "2"
[1]=> string(1) "1"
["phraseLanguageId"]=> string(1) "1"
[2]=> string(4) "BACK"
["phraseKey"]=> string(4) "BACK"
[3]=> string(6) "Back"
["phraseContent"]=> string(6) "Back"
}
}
And thats my function:
这是我的功能:
function l($key) {
global $phrases;
return PLACEHOLDER;
}
I wonder, how can I now search the array for "phraseKey" $key from the function and get the value? Do you have any hints? Or shall I simply select each phrase with each one query (performance problems with 100 quers per load?!)?
我想知道,现在如何从函数中搜索“phraseKey”$key的数组并获得值?你有什么提示吗?还是我只需为每个查询选择每个短语(每负载100个quers的性能问题?!)?
Cheers and Thanks!
欢呼和谢谢!
2 个解决方案