
正文
php显示数据库表名 php查询数据表
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何用php获取数据库信息并显示
获取ppq数据库的所有表名的代码:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("数据库系统连接失败!");
$result=mysql_list_tables($dbname);
if(!$result)
die("数据库连接失败!");
while($row=mysql_fetch_row($result))
{
echo
$row[0]."
";
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
--
列出
MySQL
数据库中的表
说明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一个数据库名并返回和
mysql_query()
函数很相似的一个结果指针。用
mysql_fetch_array()或者用mysql_fetch_row()来获得一个数组,数组的第0列就是数组名,当获取不到时
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
相关问答
Q1: php5以上版本,怎样查找数据库中表名,以及表名中有哪些字段名?
mysql_list_tables 在php5应该支持的php显示数据库表名,再说php显示数据库表名,向下兼容的啊帮助文档php显示数据库表名:例 1397. mysql_list_tables() 例子/b?php
$dbname = 'mysql_dbname';
if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
print 'Could not connect to mysql';
exit;
}
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
print "Table: $row[0]\n";
}
mysql_free_result($result);
?
Q2: phppdo连接的数据库怎么获取表名
$dbh是new PDO()
$dbh-exec("show tables");--获取所有表#
$dbh-exec("desc 表名");--查询表结构
Q3: PHP+MYSQL 怎样按条件查询数据库里表的名称?
mysql
有一个默认的数据库,叫做information_schema
连上这个库,执行下面的语句(你自己那可能的改下下面的sql)
//table_schema
是你的数据库名字
table_name是表名
select
*
from
tables
where
table_schema
=
'storage'
and
table_name
like
'product%'
你看看库中这个表结构就明白了,呵呵
php显示数据库表名的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php查询数据表、php显示数据库表名的信息别忘了在本站进行查找喔。




