解决php mysql查询插入中文乱码问题
解决php mysql查询插入中文乱码问题
一.中文问题其实就是经统一编码了否则就会乱码
1.数据库与php页面编码统一
2.数据库数据表字段与页面编码统一
如果做到上面两种就不存在中文乱码问题了,那么我们来看mysql中文乱码问题解决例子
1.我的mysql表如下
--
-- 表的结构 `useradmin`
--
代码如下 | |
CREATE TABLE IF NOT EXISTS `userain` ( |
上面所有的都是utf8编码了,这样我来测试一个中文
代码如下 | |
INSERT INTO `userain` (`id`, `我是中文`, `userpass`, `logins`, `logintime`, `mid`) VALUES |
我说可以正常进入也有人说肯定不行其实关键不在sql语句了,重点在于php连接mysql数据时的编码设置,如下。
页面编辑为gbk
代码如下 | |
//配置mysql数据库连接参数 ?> |
连接数据库之后提交肯定是乱码或保存不进行了,如果要解决这个mysql中文乱码问题很简单在查询处的
代码如下 | |
//配置mysql数据库连接参数 |
这样再提交你会发现就算你的页面是gbk的提交的数据保存也会成功哦
ps:对于ajax我们就一定要用uft8了,因为ajax只支持uft8模式传输数据。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.