Home >Backend Development >PHP Problem >What should I do if mysql does not display Chinese when inserting data into php?
The solution to the problem that mysql does not display Chinese when inserting data into php: first find and open mysql.ini; then add the statement "default-character-set = utf8".
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
Why does mysql not display Chinese when inserting data into php manage?
Detailed description of the problem:
When using php to insert Chinese data into the Mysql database, garbled characters are displayed in the database
I wrote The php code inserts a Chinese field value into the mysql database. When viewed in phpMyadmin, the display is garbled. When viewed in the mysql console, it is also garbled. I have changed the sorting rule of each field to uft8_general_ci. When directly inserted in phpmyadmin, the display is normal. In Mysql console direct insertion also shows normal, but it is not normal when inserted through php. I also wrote header("Content-Type: text/html;charset=utf-8");
<?php header("Content-Type:text/html;charset=utf-8"); if($con=mysqli_connect('localhost','root','')){ echo '连接成功'; } else{ echo '连接失败'; } if(mysqli_select_db($con,"test")){ echo '选择数据库成功'; } else{ echo '选择数据库失败'; } $str="insert into students(name,age)values('周杰伦','23')"; if(mysqli_query($con,$str)){ echo '插入成功'; } else{ echo '插入失败'; } mysqli_close($con);//关闭数据库 ?>
in the php code.
Solution:
I found the key to the problem. The problem lies in the missing sentence default-character-set = in the mysql.ini configuration. utf8, I installed mysql myself using this software after installing wampserver. His mysql.ini does not have that sentence, and if you add this sentence, you cannot add it randomly. It must be added to the location pointed out in my picture client
Use show variables like 'character_set_%; to view the character encoding after modifying the ini file as shown below
Recommended study: "PHP video tutorial》
The above is the detailed content of What should I do if mysql does not display Chinese when inserting data into php?. For more information, please follow other related articles on the PHP Chinese website!