Home > Article > Backend Development > How to solve the garbled problem of php import database
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.
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!