[英]how to display the database table names list in codeigniter
如何使用给定的语法在 CodeIgniter 中显示数据库表名列表:
$tables=$this->db->query("SHOW TABLES LIKE '%Demo%'");
You can use this:你可以使用这个:
$tables = $this->db->list_tables();
foreach ($tables as $table)
{
echo $table;
}
You have to specify the database name
.您必须指定
database name
。
Check this,检查这个,
SHOW TABLES FROM `database-name` LIKE '%a%'
See mysql documentation here请参阅此处的mysql 文档
To get table names,要获取表名,
$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.
}
Try with information_schema.tables
尝试使用
information_schema.tables
Example:例子:
$query = $this->db->query("SELECT * FROM information_schema.tables WHERE **** ");
$result = $query->result_array();
return $result;
Go through this Chapter 19 INFORMATION_SCHEMA
Tables阅读 本章第 19 章
INFORMATION_SCHEMA
表
EDIT 01编辑 01
$this->db->list_tables();
$this->db->like('name', 'field');
This will give table names as an array.这将把表名作为一个数组。
$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');
Then to display them as a comma-separated list:然后将它们显示为逗号分隔的列表:
echo implode(', ', $tables);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.