开发者

How to resolve mysql text encoding issue

I'm struggling with a mysql import issue and the usual remedies don't seem to be working. I'm trying to copy fields from one database to another (both Drupal systems).

Running "show table status on the databases" I notice that the origin table is utf8_bin and the destination table is utf8_general_ci.

I'm currently doing the import like this:

$olddb = mysql_connect("localhost", "user", "password");
mysql_select_db("origin", $olddb);
$result = mysql_query("set names utf8", $olddb);
开发者_如何学JAVA
$newdb = mysql_connect("localhost", "user", "password");
mysql_select_db("destination", $newdb);
$result = mysql_query("set names utf8", $newdb);

$result = mysql_query("select first_name from origin_table", $olddb);
$row = mysql_fetch_array($result);

$query = "update destination_table set first_name = \"".$row["first_name"]."\"";
$result = mysql_query($query, $olddb);

The text looks like its importing correctly but when I try and edit the same fields in Drupal, I get the following weird question-mark characters between every character.

Fields in Safari browser

How to resolve mysql text encoding issue

Fields in Firefox browser

How to resolve mysql text encoding issue

Any ideas?


How are you outputting the data from PHP->browser? You'd need to issue the appropriate headers to tell the browser to expect UTF-8 text, e.g:

header("Content-Type: text/plain; charset=utf-8");

Given the "weird" characters, I'm guessing FF is seeing the text as something non-unicode, like iso8859-1 and assuming 1 byte/character.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜