如果要显示mysql一个指定数据库的表名的话方法很简单,mysql提供了一个show tables命令,它返回的是一个数据,下面来看我做的详细实例,经过测试完全可用,代码如下:
- $cn = mysql_connect('localhost','root','root');
- mysql_select_db('test',$cn);
- print_r(get_tables());
- /*输出结果
- array
- (
- [0] => abc
- [1] => cn_user
- [2] => test1
- )
- */
- 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))
- {//开源代码Vevb.com
- $result[]=$rows;
- }
- return $result;
- }
新闻热点
疑难解答