`

解决MySQL乱码问题

阅读更多

原文出处:http://article.phpfans.net/article/php/y1171770260_14259.html

【解决php读取数据库乱码】

仍以数据库mysqlcode为例

<?php 
$conn 
mysql_connect("localhost","root","");
mysql_query("set names 'gbk'");//这就是指定数据库字符集,一般放在连接数据库后面就系了
mysql_select_db("test");

$sql "select * from mysqlcode";
$result mysql_query($sql,$conn);

?>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<
title>mysql 字符编码</title>
</
head>

<
body>
<
table width="300" height="32" border="1" align="center" cellpadding="0" cellspacing="0"
  <
tr>
    <
td width="71" align="center">id</td>
    <
td width="229" align="center">内容</td>
  </
tr>
 <?
php while($row mysql_fetch_assoc($result)){
 echo 
"  
 <tr>
    <td align="
center">".$row['id']."</td>
    <td>"
.$row['content']."</td>
  </tr>"
;
}?>  
</
table>
</
body>
</
html>
<?
php mysql_free_result($result);?> 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics