如何使用给定的语法在CodeIgniter中显示数据库表名列表:
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater){
menu.clear()
}
答案 0 :(得分:7)
您可以使用:
$tables = $this->db->list_tables();
foreach ($tables as $table)
{
echo $table;
}
答案 1 :(得分:4)
您必须指定database name
。
检查一下,
SHOW TABLES FROM `database-name` LIKE '%a%'
请参阅mysql文档here
获取表名,
$tables=$this->db->query("SELECT t.TABLE_NAME AS myTables FROM INFORMATION_SCHEMA.TABLES AS t WHERE t.TABLE_SCHEMA = 'database name' AND t.TABLE_NAME LIKE '%a%' ")->result_array();
foreach($tables as $key => $val) {
echo $val['myTables']."<br>";// myTables is the alias used in query.
}
答案 2 :(得分:3)
尝试使用information_schema.tables
示例:
$query = $this->db->query("SELECT * FROM information_schema.tables WHERE **** ");
$result = $query->result_array();
return $result;
完成此Chapter 19 INFORMATION_SCHEMA
Tables
编辑01
$this->db->list_tables();
$this->db->like('name', 'field');
答案 3 :(得分:0)
这将以数组的形式给出表名。
$tabResults = $this->db->select('TABLE_NAME')
->from('INFORMATION_SCHEMA.TABLES')
->where('TABLE_SCHEMA', 'database-name')
->like('TABLE_NAME', 'Demo')
->get()->result_array();
$tables = array_column($tabResults, 'TABLE_NAME');
然后将它们显示为逗号分隔的列表:
echo implode(', ', $tables);