Home  >  Article  >  Backend Development  >  What should I do if garbled characters appear when inserting Chinese data into mysql using php?

What should I do if garbled characters appear when inserting Chinese data into mysql using php?

coldplay.xixi
coldplay.xixiOriginal
2020-08-21 11:39:512432browse

Solution to garbled Chinese data inserted into mysql in php: 1. Add the relevant code [mysqli_set_charset($con,'UTF8')] to the code; 2. Or add this code [mysqli_query("set names utf8" ")].

What should I do if garbled characters appear when inserting Chinese data into mysql using php?

Solution to garbled Chinese data inserted into mysql in php:

[Related learning recommendations: mysql Video tutorial

$con = mysqli_connect(DB_HOST, DB_USER, DB_PWD, $dbname) or die('数据库连接失败');
mysqli_set_charset($con,'UTF8');

Be sure to add this sentence to set the encoding format. If not added, the code will be garbled.

There is another setting method

mysqli_query(“set names utf8”);

Just replace the above code with this sentence.

What should I do if garbled characters appear when inserting Chinese data into mysql using php?

After modification:

What should I do if garbled characters appear when inserting Chinese data into mysql using php?

##Related learning recommendations:

php programming(video)

The above is the detailed content of What should I do if garbled characters appear when inserting Chinese data into mysql using php?. 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