Search code examples
phpcodeignitercodeigniter-4

In Codeigniter 4, how to display database name and table prefix?


So far in codeigniter 3 we can get database name and table prefix (as mentioned in config/database.php) from the below code lines:

echo $this->db->database;
echo $this->db->dbprefix('emp_table');

Now how can we call these values in Codeigniter 4?


Solution

  • I think in Codeigniter 4.0.1 this is what you are looking for

    
    $db = \Config\Database::connect();
    $Database = $db->database();
    $DBPrefix = $db->getPrefix();
    
    

    I hope this work for you