Reputation: 53
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?
Upvotes: 1
Views: 2347
Reputation: 654
There are some changes in CI4, Inside controller's constructor,
write:
$db = \Config\Database::connect();
define('production',$db->database);
Upvotes: 1
Reputation: 141
$this->db->database
This will work. its Access Modifiers is protected
. So this property can be accessed within the class and by classes derived from that class. So to get globally use a public
function as
public function get_db_name(){
return $this->db->database;
}
Upvotes: 0
Reputation: 990
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
Upvotes: 1