如何解决mysql文本编码问题
我正在努力解决 mysql 导入问题,并且通常的补救措施似乎不起作用。我正在尝试将字段从一个数据库复制到另一个数据库(两个 Drupal 系统)。
运行“在数据库上显示表状态”我注意到源表是 utf8_bin,目标表是 utf8_general_ci。
我目前正在执行这样的导入:
$olddb = mysql_connect("localhost", "user", "password");
mysql_select_db("origin", $olddb);
$result = mysql_query("set names utf8", $olddb);
$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);
文本看起来像是正确导入的,但是当我尝试在 Drupal 中编辑相同的字段时,我在每个字符之间收到以下奇怪的问号字符。
Safari 浏览器中的字段
Firefox 浏览器中的字段
有什么想法吗?
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);
$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
Fields in Firefox browser
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你如何从 PHP-> 浏览器输出数据?您需要发出适当的标头来告诉浏览器期望 UTF-8 文本,例如:
鉴于“奇怪”的字符,我猜 FF 将文本视为非 unicode 的内容,例如 iso8859-1 并假设1 字节/字符。
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:
Given the "weird" characters, I'm guessing FF is seeing the text as something non-unicode, like iso8859-1 and assuming 1 byte/character.