duaner1634 2014-10-06 12:54
浏览 63

使用phpmyadmin进行数据库传输 - 编码问题

I am transfering the database from one server to another server using phpmyadmin. I successfully transfered it but having issue with swedish characters. I can see the swedish characters are displaying properly within the tables but in php pages it is wrong seems like double encoded or any other problem. Can anyone help?

  • 写回答

2条回答 默认 最新

  • dsh7623 2014-10-06 13:35
    关注

    The problem could be lying in different parts. Welcome to the world of Unicode!

    1. Make sure the collation for the columns in MySQL is utf8_* (I personally prefer utf8_bin).
    2. Make sure the PHP page is telling the client that the contents are encoded with UTF8. That can/should be done in two ways:
      • Set the following header: header('Content-Type: text/html; charset=utf-8');
      • In your HTML <head> add the correct meta tag: <meta charset="utf-8">
      • (note: while in theory it's not strictly necessary to do both, as they're equivalent for the client, it's better to be redundant!)
    3. Make sure the connection with MySQL uses UTF8. That can be done by executing a simple query right after the connection to the database: SET NAMES 'utf8' (e.g. mysqli_query("SET NAMES 'utf8'"); alter it accordingly if you're using PDO or the MySQLi OOP APIs).

    Bonus: if you're using UTF8 in your PHP script, make sure you treat everything in an Unicode-safe way. So, prefer using mb_* functions to manipulate strings, use the u flag with preg_* functions, etc. And remember than UTF8 characters are variable in the number of bytes they use, from 1 to 4!

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题