Home >Backend Development >PHP Problem >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: 1. Add the relevant code [mysqli_set_charset($con,'UTF8')] to the code; 2. Or add this code [mysqli_query("set names utf8" ")].
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.
After modification:
##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!