Home >Backend Development >PHP Problem >What to do if the interaction between PHP and database is garbled
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.
#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!