dongshendie8849 2010-09-21 12:43
浏览 240
已采纳

MySQL:SHOW TABLES只返回第一个表

I am using SHOW TABLES to retrieve a list of tables in the DB. The DB has 19 tables

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }
$dbselect = mysql_select_db($dbase,$db);
if(!$dbselect) {
  die('Could not connect: ' . mysql_error());
}
$c_query=mysql_query("SHOW TABLES ",$db);
var_dump(mysql_fetch_array($c_query));

The OUTPUT only gives an array with the first table

array(2) { [0]=>  string(5) "tabl1" ["Tables_in_dbase"]=>  string(5) "tabl1" } 

Why? How do I retrieve a list of all tables in the db? Update: Looping seems to be the answer. There does not appear to be a query which returns all the entries in one query.

  • 写回答

2条回答 默认 最新

  • douluan5444 2010-09-21 12:49
    关注

    The result contains multiple rows (each table per row), try something like:

    while($row = mysql_fetch_array($c_query)) {
        var_dump($row);
    }
    

    See also the result of the query in phpMyAdmin, that also lists multiple rows.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?