Consensus: 1. First of all, it should be determined that Chinese should also be stored in varchar
2. Test using MySQL statement to view the character set <br>
show variables like "%char%"; <br>
show variables like "collatio%"; <br>
If there are inconsistencies in encoding after checking (Chinese application gbk or utf8 support), you can specifically modify the value of a certain item, for example:
<code><span><span>SET</span> character_set_client=<span>'utf8'</span>;</span></code>
1. Create database
<code><span><span>CREATE</span><span>DATABASE</span> databasename <span>CHARACTER</span><span>SET</span><span>'utf8'</span><span>COLLATE</span><span>'utf8_general_ci'</span>;</span></code>
2. Create table
<code> CREATE TABLE industry_name ( <span>...</span> ) ENGINE=InnoDB DEFAULT CHARSET=utf8; </code>
Here is the same as ordinary The only difference in creating the table is the last sentence
Test to see if utf8 is unified
——————Now you can display Chinese when viewing mysql——————
Then think Way to get Chinese in php
1. Write
<code><span>header("Content-Type</span>: <span>text/html;charset=utf8");</span></code>
in the front section of the code 2. Write
<code>mysqli_query(<span>$connection</span>, <span>"SET NAMES utf8"</span>);</code>
after the connection is established————Now you can display Chinese in the PHP page————-
Finally, if you need to use json_encode, Then you need to pay attention to the last point
<code><span>$json_string</span> = json_encode(<span>$result_row</span>, JSON_UNESCAPED_UNICODE);</code>
that is, add one more parameter to the ordinary json_encode, and now you are all done~
Reference article:
(Transfer) The perfect solution to the Chinese garbled problem of Mysql (including database creation, data import, and web pages)
A complete solution to Chinese garbled characters in MySQL
The above introduces the correct display of json_encode Chinese from database creation to PHP reading, including the content of json_encode. I hope it will be helpful to friends who are interested in PHP tutorials.