Home  >  Article  >  Backend Development  >  How to solve the garbled problem of php import database

How to solve the garbled problem of php import database

藏色散人
藏色散人Original
2021-09-12 09:52:352194browse

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!

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