Home > Article > Backend Development > What to do if garbled characters are passed into sql from php
Solution to garbled characters in php incoming sql: 1. Modify the character set to utf8 in php encoding; 2. Execute the "alter table name convert to character set utf8;" statement.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
What should I do if there are garbled characters in the sql passed to php?
About Chinese garbled characters when php is transmitted to the database? The problem
1. Modify the character set in the PHP encoding
header("Content-Type: text/html; charset=utf-8"); //一个地方 $link = @mysql_connect("localhost", "root", "root") or die("提示:数据库连接失败!"); mysql_query('SET NAMES UTF8');//两个地方,记住是utf8不是utf-8 mysql_select_db("test", $link);2. Use editing software to see if the PHP file is encoded in UTF-8## #######3. If the above two steps are not successful, you must consider the character set of the database table. Sure enough, my mistake was in the character set of the table. Execute the following statement ######
alter table 表的名称 convert to character set utf8;### Recommended learning: "###PHP Video Tutorial###"#########
The above is the detailed content of What to do if garbled characters are passed into sql from php. For more information, please follow other related articles on the PHP Chinese website!