我想在codeigniter中显示我的数据库中的表

时间:2017-02-21 09:12:52

标签: php mysql codeigniter

$this->db->query("show tables");    
$tables = $this->db->get();    
return $tables->result_array();
  

错误号码:1096
  没有使用的表
  SELECT *

2 个答案:

答案 0 :(得分:1)

使用$this->db->list_tables()从数据库中获取所有表名。

$tables = $this->db->list_tables();

foreach ($tables as $table)
{
        echo $table;
}

有关详情,请参阅文档Codeigniter Metadata

答案 1 :(得分:1)

$this->db->get()Query Builder方法,您没有使用QB来创建查询。

您应该直接在result_array()返回值上调用query(),如下所示:

$result = $this->db->query("SHOW TABLES");
$tables = $result->result_array();

如果您阅读documentation

,这一点很明显

...是的,你也可以使用list_tables()

相关问题