Home >Backend Development >PHP Problem >What should I do if garbled characters appear when writing php to mysql?

What should I do if garbled characters appear when writing php to mysql?

王林
王林Original
2020-08-19 13:27:472543browse

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")].

What should I do if garbled characters appear when writing php to mysql?

Problem restoration:

(Recommended tutorial: php graphic tutorial)

Restore the data When writing to the database, garbled characters appear as shown below:

What should I do if garbled characters appear when writing php to mysql?

Solution:

(Video tutorial recommendation: php video tutorial)

Add the following code before selecting the database

mysql_query("set names utf8");

What should I do if garbled characters appear when writing php to mysql?

Effect:

What should I do if garbled characters appear when writing php to mysql?

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!

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