How can I optimize php multi-language SQL statements by determining the value of $ _ SESSION ['language'] for every function?
public function getA(){ if($_SESSION['language']=="tc"){ $sql="select a_tc from table"; }elseif($_SESSION['language']=="en"){ $sql="select a_en from table"; } } public function getB(){ if($_SESSION['language']=="tc"){ $sql="select b_tc from table"; }elseif($_SESSION['language']=="en"){ $sql="select b_en from table"; } }
Reply to discussion (solution)
Now, language is a part of the field and can be directly spliced into SQL.
You can optimize the table, set a language field, and use $ _ SESSION ['language'] to retrieve data:
Select content from table where language = $ _ SESSION ['language']
In this way, no matter how many other languages are used, the scalability is good.
$sql = "select a_$_SESSION[language] from table";
However, you need to specify the default value. when you first enter, there is no $ _ SESSION ['language '].
However, your code is not processed.
# The 2 solution is inappropriate.
1. too large redundancy
2. Comparison