What to do if garbled characters are passed into sql from php

藏色散人
Release: 2023-03-14 13:10:02
Original
1953 people have browsed it

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.

What to do if garbled characters are passed into sql from php

#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

What to do if garbled characters are passed into sql from php

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);
Copy after login

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;
Copy after login
### 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template