PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] how to display the database table names list in codeigniter

 March 05, 2022     codeigniter, php     No comments   

Issue

How to display the database table names list in CodeIgniter using given syntax:

$tables=$this->db->query("SHOW TABLES LIKE '%Demo%'");

Solution

You have to specify the database name.

Check this,

SHOW TABLES FROM `database-name` LIKE '%a%' 

See mysql documentation here

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.
 }


Answered By - Niranjan N Raju
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,217,631

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing