这个是从Excel导入mqsql的页面
<!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=utf-8" />
<title>无标题文档</title>
</head>
<?php$mysql_server_name='localhost'; 
$mysql_username='test'; 
$mysql_password='123456'; $conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password); mysql_select_db("beta_poreal",$conn);$row = 1;
$handle = fopen("tbl_portaldata.csv","r");
while ($data = fgetcsv($handle, 1000, ",")) {
   $sqlstr1 = "insert into tbl_portaldata (route,addresscard,address,checkdate,personnelcard,personnel,fettle,apparatus) values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]')";
 mysql_query($sqlstr1)or die (mysql_error());
   
         }
fclose($handle);
echo "ooooookkkkkkk!";
?> 
<body>
</body>
</html>//////////////////////////////////////////////////////////////////////////
这个是读取数据的页面<!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=utf-8" />
<title>excel3</title>
</head><?php$mysql_server_name='localhost'; 
$mysql_username='test'; 
$mysql_password='123456'; $conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password); //mysql_query("set names 'gbk'");
//mysql_query("set names 'utf-8'");
mysql_select_db("beta_poreal",$conn);$sql="select * from tbl_portaldata ";
$rest=mysql_query($sql);
echo $sql;
  ?>
<body>
<table width="798" border="1">
  <tr>
    <td width="83"><div align="center"> 路线<br /></div></td>
    <td width="86"><div align="center">地址卡</div></td>
    <td width="85"><div align="center">地址</div></td>
    <td width="101"><div align="center">巡查时间</div></td>
    <td width="133"><div align="center">人员卡</div></td>
    <td width="84"><div align="center">人员</div></td>
    <td width="96"><div align="center">状态</div></td>
    <td width="78"><div align="center">仪器</div></td>
  </tr> 
 
  <?php
  while($row=mysql_fetch_array($rest))
  {
  ?> <tr> 
 
    <td><div align="center"><? echo $row["route"]         ?></div></td>
    <td><div align="center"><? echo $row["addresscard"]    ?></div></td>
    <td><div align="center"><? echo $row["address"]       ?></div></td>
    <td><div align="center"><? echo $row["checkdate"]     ?></div></td>
    <td><div align="center"><? echo $row["personnelcard"] ?></div></td>
    <td><div align="center"><? echo $row["personnel"]     ?></div></td>
    <td><div align="center"><? echo $row["fettle"]        ?></div></td>
    <td><div align="center"><? echo $row["apparatus"]     ?></div></td>
    </tr>
   <?
   }
   ?> 
  
</table>
</body>
</html>

解决方案 »

  1.   

    mysql_query("set names big5'"); 执行这个没有用?
      

  2.   


    导入数据库时
    mysql_query("set names 'utf8'"); 
    此外建议最好将从excel读出的均转成utf-8,然后再存入数据库读出时同样 mysql_query("set names 'utf8'"); 
      

  3.   

    excel 导出的问题 试试导出成utf8
      

  4.   

    我导出遇到过乱码,改了编码就ok了
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    这样还不行,我就不知道原因了。
      

  5.   

    现在乱码问题解决了,先要把Excel文件转成utf-8格式的txt然后再另存为csv格式的文件,这样导入的就会是utf-8格式的了!
    可是又有新问题了,就是导入的每列只要第一个字符是汉字的,插入数据库就会为空,读出来的也是空白,除了那列第一个字符不是汉字的就可以读出显示出来,真的晕死了,谁知是怎回事,多谢了!
      

  6.   

    肯定还是字符的问题....没有全部解决...
    看看这个:
    http://www.oneways.cn/blog/post/69.html