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 ).
Copy codeThe 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 <count ($ key1); $ I ++ ){
For ($ j = 0; $ j <count ($ key2); $ 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;
}