Thinkphp3 troubleshooting mssql database garbled code

Source: Internet
Author: User
This article describes how to query mssql database garbled by thinkphp3. If you need it, refer

This article describes how to query mssql database garbled by thinkphp3. If you need it, refer

Thinkphp query mssql database garbled reason is ThinkPHP default for UTF-8, and msmsql database is Simplified Chinese version, the storage is GB2312 Encoding

Solution:

1: Open Db. class. php In ThinkPHP \ Lib \ Core, and add
2: In Db. class. in php, find function select () and add a $ result = iconv2utf8 ($ result) to $ result = $ this-> query ($ SQL ).

The Code is as follows:


Public function iconv2utf8 ($ Result ){
$ Row = array ();
$ Key1 = array_keys ($ Result); // obtain the key value of the array of the query Result $ Result
// Print_r ($ key1 );
$ Key2 = array_keys ($ Result [$ key1 [0]);
// Obtain the key value of the first array ($ key1 [0]) of the query Result $ Result.
// Print_r ($ key2 );
For ($ I = 0; $ I
For ($ j = 0; $ j // Encode the query Result to a UTF-8 and save it to $ Row, and the $ Row and $ Result keys are consistent with the value
$ Row [$ key1 [$ I] [$ key2 [$ j] = iconv ('gb2312', 'utf-8 ', $ Result [$ key1 [$ I] [$ key2 [$ j]);
}
}
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.