The solution for PHP to be unable to insert Chinese into mysql: first convert the encoding of the string str from "in_charset" to "out_charset"; then use the pdo object to execute the statement "set names gbk;"; finally execute the insertion. .
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Solution to the problem that PHP cannot insert Chinese into Mysql
string iconv ( string $in_charset , string $out_charset , string $str );
Convert the encoding of string str from in_charset to out_charset;
First convert the character type from the value in the form using the above function.
For example: $content = iconv('utf-8','gbk',$content);
Then, use the pdo object to execute the statement set names gbk;
Then, perform the insert.
The most important thing is that when creating a table in mysql, you must set the character type of the table and the default character type of the fields in the table to gbk.
Then server database result client is set to gbk.
To sum up, you can insert it.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if php cannot insert Chinese into mysql?. For more information, please follow other related articles on the PHP Chinese website!