从mysql 5.5降级到5.1,utf-8 general_ci

从mysql 5.5降级到5.1,utf-8 general_ci

问题描述:

i am using wamp for localhost, its mysql version is 5.5. After i finished my website i wanted to upload it to my website (shared hosting). which runs (5.1) but i cant insert arabic letters anymore.

when i insert any field in arabic, it gets stored as weird characters "ضووع".

it was doing great on my pc, but not online.

the database is myisam by default, but all tables are innodb with utf8_general_ci. also this is the same database i used on my machine (innodb by default) (I've imported it into my new database on the shared hosting).

so far i tried those things after making the connection

mysql_set_charset('utf8');

and

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_unicode_ci'");

what can i do more?

我正在使用wamp for localhost,它的mysql版本是5.5。 在我完成我的网站后,我想将其上传到我的网站(共享主机)。 运行(5.1),但我不能再插入阿拉伯字母了。 p>

当我在阿拉伯语中插入任何字段时,它会被存储为奇怪的字符“ضÙÙØ¹”。 p>

它在我的电脑上运行得很好,但不是在线。 p>

默认情况下数据库是myisam,但是所有表都是innodb,带有utf8_general_ci。 也这是同一个数据库 我在我的机器上使用(默认情况下是innodb)(我已将它导入我在共享主机上的新数据库中)。 p>

到目前为止我在连接后尝试了这些东西 p >

  mysql_set_charset( 'UTF8'); 
 代码>  PRE> 
 
 

和 p>

   mysql_query(“SET NAMES'utf8'”); 
mysql_query(“SET CHARACTER SET utf8”); 
mysql_query(“SET COLLATION_CONNECTION ='utf8_unicode_ci'”); 
  code>  pre> 
 
 我还能做些什么? p> 
  div>

this happened to me once, i was using htmlentities() , but when i used htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); the problem solved.

hope you have the same problem.

Provided you are using mysql_set_charset('utf8'); and not getting any errors when inserting data, that means you are correctly giving the database utf-8. On another side, you could have tables defined in some other charset, such as Windows-1256 (labeled 'cp1256' by MySQL), but that doesn't seem possible from the output you see, which is UTF-8 decoded as Windows-1252.

So the possibility I see is that you are echoing data from the database, and seeing this strings. You need to tell the browser the data is in UTF-8 as well, before sending any output:

<?php
header("Content-Type: text/html; charset=utf-8"); 

If you are already doing this or this doesn't help, your data was probably incorrectly converted in the import process.

If this is the case, and you can reimport, ensure that when exporting the data comes out as utf-8, and when importing the exported data, it is treated as utf-8.