thinkphp3 query mssql database encryption solution sharing
- 2020-12-22 17:36:30
- OfStack
When thinkphp queries mssql database, the reason is that ThinkPHP defaults to ES4en-8, while msmsql database is simplified Chinese version and stores GB2312 encoding
Solutions:
1: Open Db.class.php at ThinkPHP\Lib\Core and add at the end
2: Find function select() at Db.class.php, at $result = $this-
>
query($sql); Add a $result = iconv2utf8($result) to make OK
public function iconv2utf8($Result) {
$Row=array();
$key1=array_keys($Result); // Fetch query result $Result The key value of the array of
//print_r($key1);
$key2=array_keys($Result[$key1[0]]);
// Fetch query result $Result The first 1 An array ( $key1[0] The key value)
//print_r($key2);
for($i=0;$i<count($key1);$i++) {
for($j=0;$j<count($key2);$j++) {
// Change the encoding of the query result UTF - 8 And deposit $Row And, $Row with $Result Keys and values 1 to
$Row[$key1[$i]][$key2[$j]]=iconv('gb2312','utf-8',$Result[$key1[$i]][$key2[$j]]);
}
}
retrun $Row;
}