【PHP】解决数据库查询出来的中文内容显示为问号“??”
方法一:在数据库连接后执行: mysql_query('SET NAMES utf8');
代码:
$dbconn=mysql_connect("localhost", "root","root");
$dbconn->query("set names utf8");
方法二:使用mysql_query函数
$dbconn=mysql_connect("localhost", "root","root");
mysql_query("set names 'utf8'",$dbconn);
经测试,方法一在我这没成功,方法二成功。
展示全部代码:
<!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" />
<style type="text/css">
<!--
body,table{
font-size:13px;
}
table{
table-layout:fixed;
empty-cells:show;
border-collapse: collapse;
margin:0 auto;
border:1px solid #cad9ea;
}
th{
height:22px;
font-size:13px;
font-weight:bold;
text-align:center;
}
td{
height:20px;
}
.tableTitle{font-size:14px; font-weight:bold;}
</style>
<title>数据库结构--本地</title>
</head>
<body>
<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>
</body>
</html>
相关文章
- Php面试问题_php面试常问面试题
- 笛卡尔积 php,PHP笛卡尔积实现算法示例
- PHP连接linux并执行命令,php实现ssh远程连接服务器并操作服务器,PHP跨服务器执行shell脚本
- PHP专业连接MySQL:实现快速代码.(php连接mysql数据库代码)
- PHP中如何连接MySQL数据库?(php怎么连接mysql数据库)
- 快速访问MSSQL数据库:PHP实现(php访问mssql)
- 配置PHP实现MySQL数据库连接(php连接mysql配置)
- PHP如何关闭MySQL数据库连接(php关闭mysql连接)
- PHP与MySQL:如何实现连接?(php怎么连mysql)
- PHP文件快速导入MySQL数据库(php文件导入mysql)
- PHP调用MSSQL数据库:开启新的数据库探索(用php调用mssql)
- 检测PHP对MSSQL数据库操作的能力(检测php_mssql)
- 快速学会:PHP连接SQLServer数据库(php连接sqlserver数据库)
- Linux操作系统下的PHP编译器使用技巧(linux php编译器)
- 使用PHP连接MSSQL数据库的实例示范(php连接mssql例子)
- 使用PHP实现远程连接MSSQL数据库(php远程连接mssql)
- 用PHP访问本地MSSQL数据库的实现方法(php访问本地mssql)
- PHP连接MSSQL实现数据库操作(php用mssql)
- 服务器深入比较:PHP数据库与MSSQL服务器(php数据库和mssql)
- PHP如何操作MSSQL数据库(php怎样使用mssql)
- 从PHP操作MS SQL:解决方案指南(php如何使用mssql)
- PHP实现MSSQL数据库分页功能(php分页类 mssql)
- Php与Mssql数据库的结合:强大联合力量(php mssql数据库)
- 如何在PHP中使用MySQL数据库(mysql中php)
- 检查PHP Redis环境实现快速可靠性服务(检查php redis)
- PHP和Mysqlweb应用开发核心技术第1部分Php基础-1开始了解php
- 第二章PHP入门基础之php代码写法
- PHP获取php,mysql,apche的版本信息示例代码