set names utf8前提是你的数据库编码为utf8格式,并且你的页面显示时charset=utf8
如果是软件查看乱码,我的建议是换phpmyadmin.设定字符集查看。

解决方案 »

  1.   

    回gu1dai:
    我已经设定了数据库的编码格式为utf8
    下面是程序,很简单
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8"></head>
    <?php
    $link=mysql_connect("localhost","","") or die("connect fail");
    mysql_query("set names 'utf8'") or die("set fail");
    mysql_select_db("test") or die("select fail");
    mysql_query("ALTER DATABASE `test` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die("alter fail");
    mysql_query("create table if not exists test(theme varchar(40) not null)") or die("query1 fail");
    mysql_query("insert into test values(\"███【语课】███\")") or die("query fail");
    $result=mysql_query("select * from test") or die("query fail");
    while($row=mysql_fetch_array($result))
    echo $row[0];
    mysql_close($link);

    ?>
    </html>
      

  2.   

    除非你的这个程序文件是用utf-8编码保存的,否则"███【语课】███"需要做编码转换!
      

  3.   

    把数据库字符集设为gbk,问题解决了。