set names 'utf8'
header("Content-Type: text/html; charset=utf-8");

解决方案 »

  1.   

    mysql_query("set names utf8;");
    加油啊 
      

  2.   

    一:在DW面页属性里设置php文件编码为utf-8;
    二:创建数据库编码时用utf-8;
    三:连接数据库加上 mysql_query("set names utf8;"); 
    四:因为你的数据库为utf-8,汉字在数据库中为乱码,当然就搜索不了汉字了!
      

  3.   

    谢谢各位朋友的指点。我说下目前情况:PHP文件我用的UTF8格式保存
    链接数据库的时候用了:mysql_query("set names 'utf-8'"); 
    公共的页面上我加了header("Content-Type: text/html; charset=utf-8");
    数据库,我使用phpMyAdmin建立的,现在所有的“整理”都显示:utf8_general_ci,数据库、表、字段。
    能做的都做了,死活搜索不了,还有就是我用自己的PHP代码插入的数据自己读取没问题,在phpmyadmin里看到的是乱码。
      

  4.   

    这个问题就很妖怪了……难道是RPWT?贴点你的原始数据和搜索的代码出来看看呢……
      

  5.   

    自己插入读取没有问题,说明程序正常.
    至于在phpmyadmin里看到的是乱码,和你phpmyadmin的设置还有关系呢.比如它的连接
      

  6.   


    那么搜索不了,提示:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\php\include\db_mysql.class.php on line 43Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in E:\php\include\db_mysql.class.php on line 45是什么原因呢?附数据库操作代码:
    <?php
    class dbutil {
    private $con;
    function __construct() 
    {
    global $dbhost,$dbuser,$dbpass,$dbname;
    $this->con = mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_query("set names 'utf-8';"); 
    mysql_select_db($dbname);
    } function __destruct() 

    mysql_close($this->con);
    } function query($sql)
    {
    mysql_query($sql);
    } function query_array($sql)
    {
    $result = array(); 
    $tmp = mysql_query($sql);
    while($row = mysql_fetch_array($tmp))
    $result[] = $row;
    mysql_free_result($tmp);
    return $result;
    } function query_object($sql)
    {
    $tmp = mysql_query($sql);
    $result = mysql_fetch_object($tmp);
    mysql_free_result($tmp);
    return $result;
    } function query_field($sql)
    {
    $result = null;
    $tmp = mysql_query($sql);
    if($row = mysql_fetch_array($tmp))
    $result = $row;
    mysql_free_result($tmp);
    return $result[0];
    }
    }
    ?>
      

  7.   


    mysql_query("set names 'utf8'"); 如果页面是utf-8的,存取数据时只要加上这一条就行了
      

  8.   

    我想应该跟mysql也有关系吧?数据库都要搭配设置的。
      

  9.   

    http://download.csdn.net/source/553846
    看看这个?
      

  10.   

    it's    set names 'utf8' not     set names 'utf-8'
      

  11.   

    谢谢各位朋友的热心解答。问题得到解决。
    总结一下:数据库、表、自动全部使用utf8_general_ci
    php文件用utf8保存
    加了一句:header("Content-Type: text/html; charset=utf-8");
    后面这个大概比较关键:mysql_query("set names utf8;");
    mysql_query("SET character_set_connection='utf8', character_set_results='utf8', character_set_client='utf8'");
    另外就是写代码不能太粗心。从这点来说,PHP的错误提示明显不如.net的错误提示人性化。.net里的错误提示基本一看就知道怎么回事。php的错误提示,反正我看了以后,找了半个小时,原来是SQL语句写错了:select % from ....
      

  12.   

    早说这个错误,就知道和所谓encoding基本没有任何关系。这个问题出现也不是一次两次了……还是一而再、再而三的出现……
      

  13.   


    一般是你的SQL语句不正确,不能查询。
      

  14.   

    看贴来了,我也面临乱码到问题,好恼火,phpmyadmin里面显示正常,打开网页就出错了