How to access DB config in CodeIgniter?

Pretty much all the config values are accessible via $this->db (take a look at system/database/DB_driver.php).

That's what worked for me...none of the other suggestions here did.

As an example

$config = [ 
     'host'     => $this->db->hostname,
     'port'     => '3306',
     'username' => $this->db->username,
     'password' => $this->db->password,
     'database' => $this->db->database
];

I don't have enough rep to comment on Matt Browne's correct answer but just adding a bit incase anyone forgets...

load the db driver like so first:

$this->load->database();

then you can easily access what you need:

$this->db->hostname
$this->db->username
$this->db->password
$this->db->database

Tags:

Codeigniter