mysql与php文件选择gbk编码时,写入数据库出现乱码

来源:百度知道 编辑:UC知道 时间:2024/06/17 07:38:16
原来二者都在utf8时,也是乱码,可是换到gbk之后依旧是这样。。。

下面列出数据库相关表的字段属性,是从SQLyog中获取的
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
item_book CREATE TABLE `item_book` (
`item_id` int(11) NOT NULL auto_increment,
`cate_id` int(3) default NULL,
`item_name` text NOT NULL,
`author` varchar(20) NOT NULL,
`image_url` text,
`press` varchar(30) NOT NULL,
`rank` int(11) default '0',
`price` float(8,2) NOT NULL,
`discount` int(2) NOT NULL,
`summary` text NOT NULL,
`total_pages` int(4) default NULL,
`pdf_url` text,
PRIMARY KEY (`item_id`

你要确定你的页面也是GBK~~

如果不是的话~~强制到MYSQL的字符编码

如果你用非OO的mysqli
那么就是执行SQL语句
mysqli("Set Names 'GBK'");

最保险在连接数据库后~就直接调用下