php + sqlserver2012 connect to the database, the query data appears to give Chinese Chinese garbled

When writing code, when Chinese data appears, it will query error on the browser, will echo the sql statement came out, found no garbled, or normal way, then the corresponding statement into SQL server2012 which executes It is normal, troubled for a long time.

SQL statement is part of the code is as follows:

$sql1 = "SELECT * FROM t_user_expert WHERE user_name ='".$user_name."' AND password ='".$password."'";
echo $sql1; die();

The results from the query has been empty, then try to take out the Chinese from the database echo in the browser, the result is found

������

Later, I noticed when the original is here with php code of UTF-8 saved, but also the content header

header("content-Type: text/html; charset=utf-8");

And there's a database coding is GBK encoding, resulting in the coding error, so the php file back to GBK coding saved and changed header

header("content-Type: text/html; charset=gb2312");

Query results are normal, the problem is solved.

Guess you like

Origin www.cnblogs.com/stupidwf/p/11786120.html