Home >Backend Development >PHP Problem >What to do if the interaction between PHP and database is garbled

What to do if the interaction between PHP and database is garbled

藏色散人
藏色散人Original
2021-12-15 10:20:051824browse

Solutions to garbled characters interactively between PHP and the database: 1. Change the mysql character encoding to utf8_general_ci; 2. Set the character encoding in the PHP file.

What to do if the interaction between PHP and database is garbled

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

What should I do if Chinese garbled characters appear when interacting with PHP and SQL database?

1 When PHP writes to the database, garbled characters occur

As shown in the picture, put the proofreader over to see if it is something else. What language

Click to modify and change the character encoding to utf8_general_ci

2 When PHP reads the database to the page, garbled characters occur

As shown in the figure below

Even if the character encoding is set in the PHP file, it is not enough

Select the character set when creating a connection to the database. In this way, it will be set to the UTF8 format when it is taken out from the database

##Normal display

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What to do if the interaction between PHP and database is garbled. 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