How to write php multi-language SQL statements

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.