THINKPHP3 Query MSSQL Database garbled solution method share _php instance

Source: Internet
Author: User

thinkphp Query MSSQL database appears garbled reason is thinkphp default for UTF-8, and Msmsql database is Simplified Chinese version, storage is GB2312 code

Workaround:

1: Open the Db.class.php in Thinkphp\lib\core, at the back of it plus
2: In Db.class.php find function Select (), in $result = $this->query ($sql), followed by a $result =iconv2utf8 ($result), OK

Copy Code code as follows:

Public Function Iconv2utf8 ($Result) {
$Row =array ();
$key 1=array_keys ($Result); The key value of the array that $result the query result
Print_r ($key 1);
$key 2=array_keys ($Result [$key 1[0]]);
The key value of the first array ($key 1[0] of the query result $result)
Print_r ($key 2);
For ($i =0 $i <count ($key 1); $i + +) {

For ($j =0 $j <count ($key 2); $j + +) {
The query result encoding is changed to UTF-8 and stored in $row, and $row and $result keys are consistent with the values
$Row [$key 1[$i]][$key 2[$j]]=iconv (' gb2312 ', ' utf-8 ', $Result [$key 1[$i]][$key]]);
}
}
Retrun $Row;
}

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.