What should I do if php cannot insert Chinese into mysql?

藏色散人
Release: 2023-03-09 18:20:01
Original
2426 people have browsed it

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. .

What should I do if php cannot insert Chinese into mysql?

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 );
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template