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

coldplay.xixi
Release: 2023-03-04 22:12:01
Original
2431 people have browsed it

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('数据库连接失败');
Copy after login
mysqli_set_charset($con,'UTF8');
Copy after login

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

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!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!