建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > MYSQL学习 > 使用php列出mysql数据库所有表

使用php列出mysql数据库所有表

时间:2015-03-30 16:30:45  来源:免费模板网 作者:风雪 阅读次数 tags网站技巧

有时候想用程序知道数据库里面有多少表?在表多的时候不是很好找,小班收集了下面的文章给大家分享
php列出MySQL数据库中所有表二种方法,PHP代码如下:
  1. function list_tables($database)  
  2. {  
  3.     $rs = mysql_list_tables($database);  
  4.     $tables = array();  
  5.     while ($row = mysql_fetch_row($rs)) {  
  6.         $tables[] = $row[0];  
  7.     } //开源代码phpfensi.com 
  8.     mysql_free_result($rs);  
  9.     return $tables;  

但由于mysql_list_tables方法已经过时,运行以上程序时会给出方法过时的提示信息,如下:

Deprecated: Function mysql_list_tables() is deprecated in … on line xxx 

一个处理办法是在php.ini中设置error_reporting,不显示方法过时提示信息.

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED

另一个方法是使用PHP官方推荐的替代做法:

  1. function list_tables($database)  
  2. {  
  3.     $rs = mysql_query("SHOW TABLES FROM $database");  
  4.     $tables = array();  
  5.     while ($row = mysql_fetch_row($rs)) {  
  6.         $tables[] = $row[0];  
  7.     }  
  8.     mysql_free_result($rs);  
  9.     return $tables;
  10.  

本文地址:https://www.freemoban.com/mysql/2015/0330/1121.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!