Home  >  Article  >  Backend Development  >  How to solve the problem of garbled characters in thinkphp3 query mssql database

How to solve the problem of garbled characters in thinkphp3 query mssql database

不言
不言Original
2018-06-19 15:25:382037browse

This article mainly introduces the solution to garbled characters in thinkphp3 query mssql database. Friends who need it can refer to it

The reason why thinkphp queries mssql database with garbled characters is that ThinkPHP defaults to UTF-8, and the msmsql database is simplified The Chinese version stores GB2312 encoding

Solution:

1: Open Db.class.php in ThinkPHP\Lib\Core and add
2 at the end: Db.class.php finds function select(), 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);  //取查询结果$Result的数组的键值          
 //print_r($key1);          
 $key2=array_keys($Result[$key1[0]]);   
 //取查询结果$Result的第一个数组($key1[0])的键值           
 //print_r($key2);                  
 for($i=0;$i<count($key1);$i++) {  
  for($j=0;$j<count($key2);$j++) {                        
   //取查询结果编码改为UTF-8,并存入$Row,且$Row与$Result键与值一致                      
   $Row[$key1[$i]][$key2[$j]]=iconv(&#39;gb2312&#39;,&#39;utf-8&#39;,$Result[$key1[$i]][$key2[$j]]); 
  }         
 }       
 retrun $Row;  
}

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About thinkPHP’s method of implementing batch deletion

About thinkPHP3.2’s implementation of paging custom styles Method

About thinkPHP’s built-in string interception function method

##

The above is the detailed content of How to solve the problem of garbled characters in thinkphp3 query mssql database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn