douqudi5282 2010-10-06 00:49
浏览 33

LAMP UTF-8错误地保存到MySQL数据库

I've converted my database from Latin 1 to UTF8, and using phpPMyAdmin you can enter data and display it correctly. However viewing in the pages I've developed in PHP and editing it using my simple CMS saves characters that must be incorrectly coded.

I've spent a few hours researching and eventually came up with this code snippet:

mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn_products);

Which when placed before a DB operation corrects the issue - marvellous!

I've done some further research, and have (I believe) discovered a way to make this permanent across an entire MySQL Server, but I would like to permanently change it per database as a majority of the sites using the server are Latin 1, and need to stay that way.

Can anybody point me in the right direction please?

  • 写回答

1条回答 默认 最新

  • dongtang4954 2010-10-06 01:05
    关注

    You cannot do it per-database unfortunately, it's either set by the client application or the server if a client doesn't state anything. You only have to set it once per session, so just teaching yourself to let a always follow up a mysql_select_db() that is probably there be with mysql_query('SET NAMES utf8;') (or whatever character set you need) should do the trick.

    评论

报告相同问题?

悬赏问题

  • ¥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的速度时间图像)我想问线路信息是什么