PHP技术分享-久趣源码交流论坛

PHP技术分享

久趣社区【PHP学院】--一个专注用于游戏或者源码里的PHP实用性社区!
帖子
56
互动
6
阅读
1565

[PHP编程] 【PHP】解决数据库查询出来的中文内容显示为问号“??”

今天遇到一个php代码调用数据库显示的都是??

这里盲猜就是数据库编码的问题,咱们找到数据库连接的代码中,强制给一个编码的设置就可以了

$dbconn->query(“set names utf8”);

上面的代码一定要加到数据库的链接后面,给一个案例吧,这样大家能看得比较明白:

<div style="margin:0 auto;width:880px; border:1px #006600 solid; font-size:12px; line-height:20px;">
<div style="width:100%;height:30px; font-size:16px; font-weight:bold; text-align:center;">
数据库结构--本地<br />
<font style="font-size:14px; font-weight:normal;"><?php echo date("Y-m-d h:i:s"); ?></font>
</div>
<?php

$dbconn=mysql_connect("localhost", "root","root");
//$dbconn->query("set names utf8");
mysql_query("set names 'utf8'",$dbconn);
$sqlname="information_schema";
mysql_select_db($sqlname,$dbconn);
session_start();

$sql = "SELECT * FROM tables where table_schema='jtest' order by TABLE_NAME";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result))
{
//print_r($row);
?>
<div style="margin:0 auto; width:100%; padding-top:10px;">
<b class="tableTitle">表名: <?php echo $row["TABLE_NAME"] ?> </b> <br />
<?php echo $row["TABLE_COMMENT"] ?>
</div>
<table width="100%" border="1">
<thead>
<th width="70">序号</td>
<th width="170">字段名</td>
<th width="140">字段类型</td>
<th width="80">允许为空</td>
<th width="70">默认值</td>
<th>备注</td>
</thead>
<?php
$sql2 = "SELECT * FROM columns where table_name='".$row["TABLE_NAME"]."' order by COLUMN_NAME";
$result2 = mysql_query($sql2);
$num=0;
while($row2=mysql_fetch_array($result2))
{
$num = $num+1;
//print_r($row);
?>

<tr>
<td align="center"><b><?php echo $num ?></b></td>
<td><?php echo $row2["COLUMN_NAME"] ?></td>
<td><?php echo $row2["COLUMN_TYPE"] ?></td>
<td align="center"><?php echo $row2["IS_NULLABLE"] ?></td>
<td align="center"><?php echo $row2["COLUMN_DEFAULT"] ?></td>
<td><?php echo $row2["COLUMN_COMMENT"] ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
mysql_close($dbconn);
?>

</div>

 

请登录后发表评论

    没有回复内容