How to solve the garbled problem of php import database

藏色散人
Release: 2023-03-12 13:20:01
Original
2126 people have browsed it

Solution to garbled characters when importing database into PHP: 1. Connect to the database through mysqli_connect; 2. Use the "mysqli_query("set names utf8");" statement to set the encoding format to utf8.

How to solve the garbled problem of php import database

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

How to solve the garbled problem of PHP import database?

php inserts mysql Chinese data into garbled characters

$con = mysqli_connect(DB_HOST, DB_USER, DB_PWD, $dbname) or die('Database connection failed');

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");//Replace the above yellow code with this sentence.

After modification: If you have any questions, please contact me for help.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve the garbled problem of php import database. 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
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!