Server database encoding format problem
A recent project has two problems following deployment to the Aliyun server:
1, garbled problem.
2, Ajax PHP processing page inside the use of the Json_encode () function to return the JSON data, the data returned by the database can only be UTF8, if it is GBK JSON can not return.
The discovery is the database coding format problem, the website uses the encoding format to be UTF8, the database encoding format is tuned for UTF8, but the Character_set_server value or GBK.
To view the database encoding:
In the MySQL command line input: Showvariables like ' character% ';
So there are still garbled.
So I found a solution from the Internet:
In the MySQL command line input:set Character_set_server=utf8;
OK modification Successful! Returning the data is normal, but when the database service is turned off, the set Character_set_server is turned back to GBK.
So this method can only be solved temporarily.
Finally found a good workaround is to execute the SQL statement before executing the SQL statements:
$conn->query (' SET character_set_client = UTF8; ');
$conn->query (' SET character_set_results = UTF8; ');
$conn->query (' SET character_set_connection = UTF8; ');
This solution is not very personal feeling good, each execution of too many times, if you can modify the server database coding format best.
Thank you for reading, I hope to help you, thank you for your support for this site!