【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】解决数据库查询出来的中文内容显示为问号“??”的更多相关文章
- python 读取数据库中文内容显示一堆问号
需要在连接数据库时 设置编码格式 def select_db(self,db_name): self.conn = MySQLdb.connect( host = self.ip, port = se ...
- Firebug中调试中的js脚本中中文内容显示为乱码
Firebug中调试中的js脚本中中文内容显示为乱码 设置 页面 UFT-8 编码没用, 解决方法:点击 "Firebug"工具栏 中的"选项"---" ...
- 关键字中mysql数据库查询条件带中文无结果解决办法
package keyword; import java.io.UnsupportedEncodingException; import java.sql.Connection; import jav ...
- gVim 中文内容显示为乱码的解决办法
http://blog.csdn.net/sunmanzth/article/details/6143600打开vimrc文件,在vim的安装目录下可以找到该文件,或在windows下是在vim/gv ...
- php查询mysql数据库 查询条件替中文字符串变量时无法查询
$temp2 ='十年';mysql_query("SET NAMES GBK"); $res = mysql_query("select songer_name fro ...
- C#连接oracle 数据库查询时输入中文查询不出来,用plsql就可以
查询语句为:select * from Per where khmc like '%李%',其实是字符集的问题. 解决方案:在连接字符串加一个“Unicode=True;”
- 解决Mac中anaconda作图中文异常显示的问题
说明 本篇主要针对在MAC系统中Anaconda环境下,matplotlib显示不了中文的问题,提出解决Python绘图时中文显示的方法. 运行环境 macOS Mojave 10.14.6 Pyth ...
- Java程序向MySql数据库中插入的中文数据变成了问号
找到mysql的安装目录,修改my.ini文件 (1)如何找到my.ini文件 如果my.ini文件不在MySQL的安装目录下,可能放在隐藏目录,要先去找到ProgramData,(这里要先打开显示隐 ...
- 解决gdb 调试 core 文件函数名显示为问号的问题
关于gdb调试core文件总是一堆问号的问题 问题描写叙述:已经在编译选项中增加了-g,可是查看core文件时.还是一堆问号,使用的命令为:gdb -c core 解决方式:因为gdb -c core ...
随机推荐
- springboot集成rabbitmq并手动注册容器实现单个queue的ack模式
原文:https://blog.csdn.net/qq_38439885/article/details/88982373 进入正题,本文会介绍两种实现rabbitmq的ack模式的方法,分别为: 一 ...
- Arduino Tian开发板:一个功能强大的天气预报中心
每天都在出现新的连接设备. Arduino携手云平台一起加入这场战斗,于是出现了一个新的挑战者 - Arduino Tian! 使用python和经典Arduino框架,本教程将引导您将您的Ardui ...
- Bootstrap 基本模板
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- linux 用户,密码,用户组
linux 用户,密码,用户组 在root登陆的情况下: 用户密码: useradd <username> passwd <username> <提示输入密码>: ...
- 设置input 中placeholder的样式
::-webkit-input-placeholder { /* Chrome/Opera/Safari */ position: relative; top: 4px; } ::-moz-place ...
- 2019-2020-1 20199301《Linux内核原理与分析》第二周作业
第二周Linux学习笔记 文件打包与解压缩 tar工具打包 tar的解压和压缩都是同一个命令,只需参数不同,使用较方便. 创建一个包时文件名必须紧跟在 -f 之后,解包一个文件(-x参数)到指定路径的 ...
- eclipse转到idea过程中的基本设置...
1.在写mapper.xml文件中有许多黄黄绿绿的警告 - 黄色的是没有用idea链接数据库,连上就ok,不连的话,这样:Prefernces ⇒ Editor ⇒ Inspections ⇒ SQL ...
- HaspMap和ConcurrentHashMap
参考自:http://www.importnew.com/28263.html HaspMap和ConcurrentHashMap(康科瑞特哈希迈普) Java7 HashMap 不支持并发操作,Ha ...
- [ARIA] Accessible animations with reduced motion
Animations can make people sick, or worse! By adding animation toggles and listening in to the user' ...
- trigger 和 triggerHandler(),自定义事件
trigger 和 triggerHandler(),自定义事件 语法: $(selector).trigger(event,[param1,param2,...]) 1,event 必需.规定指定元 ...