方法一:在数据库连接后执行: 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>

最新文章

  1. EntityFramework、Dapper vs 草根框架性能大比拼,数据库访问哪家强?
  2. CSS基础知识之文本属性二三事
  3. SQLServer2012自增列值跳跃的问题
  4. 从键盘输入成绩,找出最高分,并输出学生成绩等级。成绩&gt;=最高分-10,为A,成绩&gt;=最高分-20,为B,成绩&gt;=最高分-30,为C,其余等级为D
  5. tomcat学习笔记2
  6. 一个自定义的C#数据库操作基础类 SqlHelper
  7. css3 3D盒子效果
  8. 【ThinkingInC++】61、非成员运算符
  9. select count(*)优化 快速得到总记录数
  10. ConcurrentLinkedQueue简介
  11. SSL 3.0曝出Poodle漏洞的解决方案
  12. angular 动态取到的html片段 在页面的展示
  13. Jenkins&#160;Jenkins结合GIT&#160;Maven持续集成环境配置
  14. 下载最新的glibc库并临时使用,而不污染原有系统环境
  15. android AES 加密解密
  16. Redis Cluster在线迁移
  17. ES6--JavaScript的第六个版本
  18. Some Java exceptions, messages and errors.
  19. error:please select android sdk
  20. 《转》Python学习(13)-Python的字符编码

热门文章

  1. 【新品发布】智能驾驶实车测试系统-VDAS
  2. JDBC课程5--利用反射及JDBC元数据(ResultSetMetaData)编写通用的查询方法
  3. 《hello-world团队》第七次作业:团队项目设计完善&amp;编码
  4. CF277B Set of Points——构造题
  5. Git - Q
  6. 52、[源码]-Spring源码总结
  7. hive 的 beeline用法
  8. 22 | MySQL有哪些“饮鸩止渴”提高性能的方法?
  9. P2701 [USACO5.3]巨大的牛棚Big Barn
  10. NetworkX系列教程(1)-创建graph