简体   繁体   中英

CodeIgniter Working with multiple Databases

I am trying to list all the mysql databases and their respective tables, I am currently using this, but can anybody recommend if there is any better way.

$q = $this->db->query('SHOW DATABASES');
$databases = $q->result_array();

foreach($databases as $db) {
  $this->db->query('USE '. $db['Database']);

  $q = $this->db->query('SHOW TABLES');
  $tables = $q->result_array();             
}

You can use the information_schema special database, which has tables that describe all the other databases, tables, and columns.

That way you only need 1 query:

SELECT table_schema, table_name
FROM information_schema.tables
ORDER BY table_schema, table_name;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM