Home >Backend Development >PHP Tutorial >Solve the problem of inserting Chinese garbled characters in php mysql query_PHP tutorial
1. The Chinese problem is actually that it has been uniformly encoded, otherwise it will be garbled
1. Unify the encoding of database and php page
2. The database data table fields and page coding are unified
If you can do the above two, there will be no Chinese garbled problem, then let’s look at the example of solving the Chinese garbled problem in mysql
1. My mysql table is as follows
--
--Table structure `useradmin`
--
The code is as follows | |||||
CREATE TABLE IF NOT EXISTS `userain` (
|
All the above are encoded in utf8, so I will test a Chinese
The code is as follows | |||||
INSERT INTO `userain` (`id`, `I am Chinese`, `userpass`, `logins`, `logintime`, `mid`) VALUES
|
I said that it can be entered normally, but some people said that it is definitely not possible. In fact, the key is not the sql statement, but the encoding settings when php connects to mysql data, as follows.
The page is edited as gbk
The code is as follows | |||||||||||||
//Configure mysql database connection parameters
?> After connecting to the database, the submission must be garbled or cannot be saved. If you want to solve the problem of Chinese garbled mysql, it is very simple.
If you submit again like this, you will find that even if your page is submitted by gbk, the data submitted will be saved successfully ps: We must use uft8 for ajax, because ajax only supports uft8 mode to transmit data. Statement: 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 Previous article:PHP implementation can be used for mysql, mssql, pg database operation class, mysqlmssql_PHP tutorialNext article:PHP implementation can be used for mysql, mssql, pg database operation class, mysqlmssql_PHP tutorial Related articlesSee more |