doujia5863 2012-05-31 11:08
浏览 26
已采纳

MySql / php utf8似乎无法正常工作

So I have a table that is 'utf8_general_ci' with the same fields.

I couldn't get any utf8 characters into it, they all showed as '????' , then I changed table to 'MyISAM' and now I can insert utf8 data from PhpMyAdmin (first time something like this happens).

But it still doesn't work from PHP side. When I insert 'āāā' it shows as '???', but the weird part is if I insert 'žžžēēē' it show as 'žžž???' so some utf8 characters work? PHP file is UTF-8

CREATE TABLE IF NOT EXISTS `company` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=5 ;

$dbConnection = mysql_connect("localhost","*****","*****");
mysql_query("SET NAMES 'utf8'", $dbConnection);
mysql_query("SET CHARACTER SET 'utf8'", $dbConnection);
mysql_select_db('cherrysystem', $dbConnection);
mysql_query("INSERT INTO `company` (`title`) VALUES ('āāčč')",$dbConnection);

RESOLVED

Ok, so problem in my case was that I had to set MySql ini file to use utf8. By default it was something else, I'm using Wamp server and it have always worked without extra configuring, but not in this case.

 character-set-server=utf8
 collation-server=utf8_general_ci
  • 写回答

1条回答 默认 最新

  • duandange7480 2012-05-31 12:14
    关注

    Obviously something is not 'Unicode' in the way you handle the data.

    Here are my top 7 usual suspects :

    • PHP file containing the code is not UTF-8 itself
    • Database connection must conform to Unicode (SET NAMES 'utf8')
    • Inserted data must be utf8 encoded if importing from a non unicode source e.g
    • Check tables and the columns used to store data
    • HTML file used to display the data is not UTF (same as point 1)
    • HTML charset declared in meta tags must be utf-8 also
    • ... no point 7 (maybe in the comments)

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么