Thinkphp3: how to solve mssql database garbled data query. Thinkphp query mssql database garbled reason is ThinkPHP default for UTF-8, and msmsql database is a simplified Chinese version, the storage is GB2312 Encoding Solution: 1: in ThinkPHPLibCor thinkphp query mssql database garbled because ThinkPHP default for UTF-8, while msmsql database is a 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;
}
Solution: 1: In ThinkPHP \ Lib \ Cor...