编码统一才能正确输出,看一下目标数据表使用的是什么编码: SHOW CREATE TABLE someTableName另外,使用EditPlus保存文件时,有没有选择utf8编码,如果右下角显示的是ANSI,另存一下,另存时选择文件编码为UTF-8.
怎么看我的数据库是不是utf8编码的?我的文件编码是utf8的,我在SQL里输入SHOW CREATE TABLE winstore可是上面有个#1046 - No database selected 而不是出现是什么编码的,是什么原因啊
先选择数据库啊,然后查看建表语句。 USE someDatabaseName
它显示的怎么是这个?建表信息,没看到是什么编码的啊 CREATE TABLE `customer` ( `cust_id` int(5) unsigned NOT NULL AUTO_INCREMENT, `cust_name` char(6) NOT NULL, `cust_password` char(15) NOT NULL, `cust_address` char(30) NOT NULL, `cust_city` char(10) NOT NULL, `cust_email` char(20) NOT NULL, `cust_phone` char(11) NOT NULL, `cust_birthDate` char(15) NOT NULL, PRIMARY KEY (`cust_id`) ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1
DEFAULT CHARSET=latin1看到没?
ALTER TABLE `customer` CHARACTER SET utf8; ALTER TABLE `customer` CHANGE `cust_name` `cust_name` CHAR(6) CHARACTER SET utf8; ALTER TABLE `customer` CHANGE `cust_password` `cust_password` CHAR(15) CHARACTER SET utf8; ALTER TABLE `customer` CHANGE `cust_address` `cust_address` CHAR(30) CHARACTER SET utf8; ALTER TABLE `customer` CHANGE `cust_city` `cust_city` CHAR(20) CHARACTER SET utf8;
还有。试试使用odbc看看。
在数据库连接文件里设置下编码
mysqli_set_charset($dbc,'gb2312'); /*确保你开启了mysqli扩展*/
php脚本开始加个
header('Content-Type:text/html;charset=gb2312')
html里
<meta http-equiv="Content-Type" Content="text/html;charset=gb2312" >
这样就可以了
如果是做中文网站的话,建议使用gb2312
因为gb2312会比utf8占的空间少一点, 传输需要的数据量也会少点,
像百度, 网易,都用的是gb2312编码的
改成:mysql_query('set names utf8');
SHOW CREATE TABLE someTableName另外,使用EditPlus保存文件时,有没有选择utf8编码,如果右下角显示的是ANSI,另存一下,另存时选择文件编码为UTF-8.
USE someDatabaseName
CREATE TABLE `customer` (
`cust_id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`cust_name` char(6) NOT NULL,
`cust_password` char(15) NOT NULL,
`cust_address` char(30) NOT NULL,
`cust_city` char(10) NOT NULL,
`cust_email` char(20) NOT NULL,
`cust_phone` char(11) NOT NULL,
`cust_birthDate` char(15) NOT NULL,
PRIMARY KEY (`cust_id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1
ALTER TABLE `customer` CHANGE `cust_name` `cust_name` CHAR(6) CHARACTER SET utf8;
ALTER TABLE `customer` CHANGE `cust_password` `cust_password` CHAR(15) CHARACTER SET utf8;
ALTER TABLE `customer` CHANGE `cust_address` `cust_address` CHAR(30) CHARACTER SET utf8;
ALTER TABLE `customer` CHANGE `cust_city` `cust_city` CHAR(20) CHARACTER SET utf8;
[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
[client]
default-character-set=utf8