How can i get value from database.php page? I mean we can access base url by using base_url()
.The base url set in config.php page like this :
$config['base_url'] = 'example.com';
The database details in database.php is like:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database_name';
I want to access the this details in my controller page.How can i do this?
There is another way that would work: you make the db settings available as config data.
You can do that by appending the following lines to the database.php file and use the filtering of your choice:
// get all configurations
$config = $db;
// be more specific
foreach($db as $key => $settings)
{
$config[$key]['hostname'] = $settings['hostname'];
// etc
}
Then you can load the data as you normally would load config values:
$this->load->config('database',TRUE);
$db = $this->config->item('default','database');
echo $db['hostname'];
// etc
<?php
include('database.php');
echo $db['default']['hostname'];
?>
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.