试试
$conn=mysql_connect ($DBhost,$DBuser,$DBpass);
mysql_select_db($DBname);
mysql_query("set names gb2312;");

解决方案 »

  1.   

    我用的是<meta name="Keywords" content="">
    <meta name="Description" content="">
    </head>
    <body>
    <?php 
    @ $db=new mysqli('localhost','root','1','books');
    if (mysqli_connect_errno()){
    echo 'error.............';
    exit;
    }
    //$sql ="insert into test2 value ('456','123');";
    $sql="select * from test2";
    $result=$db->query($sql);
    echo $result;
    $num=$result->num_rows;
    for ($i=0;$i<$num;$i++){
    $row =$result->fetch_assoc();
    echo $row['name'].'...'.$row['id'].'<br/>';
    }
    $result->free();
    $db->close();
    echo '<h1>........end ok.....';
    ?>
    </body>
    </html>在页面插入中文也不行,控制台则可以,真是晕死
      

  2.   

    直接在页面插入中文也不可以?去设置下apache的httpd.conf。
      

  3.   

    在httpd.conf里面加入AddDefaultCharset,一般这种问题容易出现在linux下,windows下没这种问题。
      

  4.   

    http://blog.chinaunix.net/u/19869/showart_121729.html在执行SQL语句前先执行一下:
    mysql_query("SET NAMES 'GB2312'");
      

  5.   

    首先要谢谢你们的热心指导,但我的问题是,现有的项目都是用的php_mysqli.dll,如果都换成php_mysql.dll,那要改的地方实在太多了啊
      

  6.   

    mysql_query("set names gb2312;"); 这种方法应该是比较实用的
      

  7.   

    最好还要header("content-type:text/html;charset=gb2312")不过我觉得还是使用UTF-8编码的好,最保险!
      

  8.   

    我用的是<meta name="Keywords" content="">
    <meta name="Description" content="">
    </head>
    <body>
    <?php 
    @ $db=new mysqli('localhost','root','1','books');
    if (mysqli_connect_errno()){
    echo 'error.............';
    exit;
    }
    //$sql ="insert into test2 value ('456','123');";
    $sql="select * from test2";
    $result=$db->query('set names gb2312');//添加一行
    $result=$db->query($sql);
    echo $result;
    $num=$result->num_rows;
    for ($i=0;$i<$num;$i++){
    .
    .
    .
      

  9.   

    sorry,只添加$db->query('set names gb2312');//添加一行
    不要$result=
      

  10.   

    太谢谢了,terry52,对你的敬仰犹如滔滔江水,连绵不绝啊。
      

  11.   

    不过terry52,有一个问题还想请教一下,$db->query('set names gb2312'这句是吧哪个的charset属性给改了呢,难道这之前我的设置有问题吗