php教程 mysql教程获取指定数据库教程所有表名
如果要显示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)) { $result[]=$rows; } return $result; }
//本站原创教程转载注明来源于http://www.bKjia.c0m保留连接地址,否则必究!
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号