Solution to garbled characters when php writes to mysql: Just set the encoding before executing the [mysql_select_db()] statement, such as: [mysql_query("set names utf8")].
Problem restoration:
(Recommended tutorial:php graphic tutorial)
Restore the data When writing to the database, garbled characters appear as shown below:
Solution:
(Video tutorial recommendation:php video tutorial)
Add the following code before selecting the database
mysql_query("set names utf8");
Effect:
Problem solved!
The above is the detailed content of What should I do if garbled characters appear when writing php to mysql?. For more information, please follow other related articles on the PHP Chinese website!