代码:<?php require_once('Connections/ConnClass.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}mysql_select_db($database_ConnClass, $ConnClass);
$query_RecClassMates = "SELECT * FROM classmates";
$RecClassMates = mysql_query($query_RecClassMates, $ConnClass) or die(mysql_error());
$row_RecClassMates = mysql_fetch_assoc($RecClassMates);
$totalRows_RecClassMates = mysql_num_rows($RecClassMates);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<table border="1" cellpadding="2" cellspacing="1">
  <tr>
    <td>classID</td>
    <td>className</td>
    <td>classSex</td>
    <td>classBirthday</td>
    <td>classEmail</td>
    <td>classPhone</td>
    <td>classAddress</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_RecClassMates['classID']; ?></td>
      <td><?php echo $row_RecClassMates['className']; ?></td>
      <td><?php echo $row_RecClassMates['classSex']; ?></td>
      <td><?php echo $row_RecClassMates['classBirthday']; ?></td>
      <td><?php echo $row_RecClassMates['classEmail']; ?></td>
      <td><?php echo $row_RecClassMates['classPhone']; ?></td>
      <td><?php echo $row_RecClassMates['classAddress']; ?></td>
    </tr>
    <?php } while ($row_RecClassMates = mysql_fetch_assoc($RecClassMates)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($RecClassMates);
?>数据库连接代码<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_ConnClass = "localhost";
$database_ConnClass = "class";
$username_ConnClass = "root";
$password_ConnClass = "123456";
$ConnClass = mysql_pconnect($hostname_ConnClass, $username_ConnClass, $password_ConnClass) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
我在MYSQL的my.ini文件里设置了default-character-set=gb2312请问怎么回事呢??

解决方案 »

  1.   

    你在PHP中连接数据库的时候,设置一下连接的字符集和数据表的字符集保持一致。
      

  2.   

    比如: $conn = new mysqli('localhost', 'root', '', 'db'); 
      $conn->query("set names gbk");
      

  3.   

    <!--
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    -->
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <?php
    error_reporting(0);
    $dbConnect=mysql_connect("localhost","root","123");
    if (!$dbConnect)
    {
    echo "<script language=javascript>alert('连接远程服务器出错!');window.location= 'login.php';</script>";
        exit; 
    }
    mysql_select_db("crm");
    mysql_query("SET CHARACTER SET GB2312");
    mysql_query("SET NAMES utf8");
    mysql_query("SET CHARACTER SET utf8");
    mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
    //echo "<br />看不到就对了<br />";  //#号截断
    ?>
    这个是连接文件代码,可以参考下
      

  4.   

    MySQL数据库编码、html页面编码、PHP或html文件本身编码要全部一致。
      1、MySQL数据库编码:建立数据库时指定编码(如gbk_chinese_ci),建立数据表、建立字段、插入数据时不要指定编码,会自动继承数据库的编码。
    数据库连接时,也有编码,可以在连接完数据库后,执行
    mysql_query('SET NAMES gbk');//将gbk换成你的编码,如utf8。    2、html页面的编码,指的是这一行的设置:
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />    3、PHP或html文件本身的编码:用editplus打开php文件或html文件,另存时,选择的编码,如果数据库和页面编码是gbk,则这儿的编码选择ansi;如果数据库和页面编码是utf-8,则这儿也选择utf-8。  4、另外要注意的是,Javascript或Flash中传递的数据是utf-8编码,如果数据库和页面编码是gbk,要进行转码,然后写入数据库。
    iconv('utf-8', 'gbk', $content);5、在PHP程序中,可以加上一行,来指定PHP源程序的编码:
    header('Content-type: text/html; charset=gbk');
      

  5.   

    建议重新导入数据库.
    1.在导入数据库时,在“整理”选项中选择“utf8_general_ci”;2.然后,就是表中各条记录,“整理”字段同样设置为“utf8_general_ci”;我刚试过了,中文已经正常显示了。
      

  6.   

    mysql设置的编译码要和你这里的连接文件的编译码要一样
      

  7.   

    编码问题  你可以把得到的信息通过iconv函数来转换为你要的字符
      

  8.   

    字符集问题,如果mysql默认安装 是utf8。
    看了你的网页编码你要求的字符集是charset=“gb2312"
    那么显示出来的当然是???了。一定要把数据库和网页编码统一,才能正确的显示。
    要么都是utf8,要么都是gb2312。