Home > Database > Mysql Tutorial > PHP MySQL获取指定数据库所有表名

PHP MySQL获取指定数据库所有表名

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:58:08
Original
1340 people have browsed it

如果要显示mysql一个指定数据库的表名的话方法很简单,mysql提供了一个show tables命令,它返回的是一个数据,下面来看我做的详细

如果要显示mysql一个指定数据库的表名的话方法很简单,,mysql提供了一个show tables命令,它返回的是一个数据,下面来看我做的详细实例,经过测试完全可用
*/

$cn = mysql_connect('localhost','root','root');
mysql_select_db('test',$cn);
print_r(get_tables());

function get_tables() //获取所有表表名
{
 $tables=array();
 $r=fetch_all("show tables");
 foreach($r as $v)
 {
  foreach($v as $v_)
  {
   $tables[]=$v_;
  }
 }
 return $tables;
}

function fetch_all($sql)
{
 $rs=mysql_query($sql);
 $result=array();
 while($rows=mysql_fetch_array($rs,mysql_assoc))
 {
  $result[]=$rows;
 }
 
 return $result;
 
}


//转载注明来源于保留连接地址!
 ?>

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template