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"; } }
即然language是字段的一部分,直接拼接成SQL就行了
你可以优化表,设置一个语言字段,通过$_SESSION['language']取数据:
select content from table where language = $_SESSION['language']
这样不管后面来多少种语言都迎刃而解了,可扩展性好
$sql = "select a_$_SESSION[language] from table";