Home >Backend Development >PHP Tutorial >Thinkphp3 query mssql database garbled solution_PHP tutorial
This article mainly introduces the solution to garbled characters in thinkphp3 query mssql database. Friends in need can refer to it
The reason why thinkphp displays garbled characters when querying the mssql database is that ThinkPHP defaults to UTF-8, while the msmsql database is a simplified Chinese version and stores GB2312 encoding. Solution: 1: Open Db.class.php in ThinkPHPLibCore and add at the end 2: Find function select() in Db.class.php, add $result=iconv2utf8($result) after $result = $this->query($sql);, and it’s OK The code is as follows: public function iconv2utf8($Result) { $Row=array(); $key1=array_keys($Result); //Get the key value of the array of query result $Result //print_r($key1); $key2=array_keys($Result[$key1[0]]); //Get the key value of the first array ($key1[0]) of the query result $Result //print_r($key2); for($i=0;$i