dongping5230 2012-12-27 03:39
浏览 62
已采纳

PHP 5.4.9 MySQL 5.5.28.3 - 选择带有UniCode字符的字段将返回空白结果

I've been searching the web for hours and nothing I find seems to help. This was working fine when I was on PHP 5.3 and MySQL 5.1. When I upgraded both of these, I realized that selects done against fields with UniCode characters in them give blank results.

The table is set to UTF8 and the field in particular has also been set to UTF8 just in case. I have a charset=utf-8 in the header area of my document.

I made two test posts in my forum, one with straight text and one with a curly quote in it. I then created a simple PHP query to fetch the two rows. The gist of the code is this:

<?php

$con = mysql_connect("XXXXX","XXXXX","XXXXX");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("XXXXX", $con);


echo "<br />";
echo "<br />";
echo "PHP 5.4.9 having issues displaying UniCode characters. MySQL 5.5.28.3. FastCGI has been removed. IIS.";
echo "<br />";
echo "<br />";


$result1 = mysql_query("SET NAMES 'utf8'");


$result = mysql_query("SELECT post_body from ubbt_posts where post_id = 358826");

while($row = mysql_fetch_array($result))
  {
  echo "Post Body without unicode: " . $row['post_body'];
  echo "<br />";
  echo "<br />";
  }


$result = mysql_query("SELECT post_body from ubbt_posts where post_id = 358825");

while($row = mysql_fetch_array($result))
  {
  echo "Post Body with unicode: " . $row['post_body'];
  echo "<br />";
  echo "<br />";
  }

mysql_close($con);

?>

The behavior is that the non-unicode post displays properly. The other one doesn't display at all. It's not that it displays a square or block instead of the quote - it doesn't show anything.

I've tried changing the mysql_fetch_array to mysql_fetch_assoc. That didn't help. I tried utf8_encode out of frustration and that didn't help either.

I'd read that some people had issues with the combo of IIS / PHP 5.4.9 / FastCGI so I deinstalled FastCGI. At least I tried my best to - the files are all gone and IIS is pointing again to the php-cgi.exe file. But PHP still reports it's using FastCGI. I think it must be seeing something in the registry? But in any case the files are gone so it really can't be. And it didn't help.

I'll try even wild ideas at this point to get it working. Any thoughts?

UPDATES:

I have now tested this with both PHP and ASP. Both languages give the identical same behavior. My result set with updated code gives these results:

Post Subject without unicode: test post without unicode

Post Body without unicode: test post with just normal characters in it, as well as xyzzy for testing.

Length of body field: 74

Post Subject with unicode: test post with unicode

Post Body with unicode:

Length of body field: 0

So with the length being checked, both ASP and PHP report the length of that field is zero.

Could it be ODBC that is having an issue? Could it be FastCGI still interfering even though I tried to remove it?

UPDATE 2 -

What I had to do to fix this is to reload the data in from a backup, into the table already set as UTF8 and the field set to UTF8. Then I had to do the set names utf8 command in the code right after the connect. I don't think FastCGI was involved here - when I reinstalled FastCGI things were still OK. I still have some niggling issues remaining but I think the table set and reload handled most of my issues.

Lisa

  • 写回答

1条回答 默认 最新

  • duanao2585 2012-12-27 03:43
    关注

    Try setting utf8 in another way -

    mysql_set_charset('utf8', $con);
    

    In place of this --

    mysql_query("SET NAMES 'utf8'");
    

    Where $con is a connection created with mysql_connect() method

    NOTE - Try to use PDO or mysqli

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)