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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 16:58:081355browse

如果要显示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

Statement:
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