Reputation: 349
I want to create a database backup tool in codeigniter. So i want to grab the database name from controller. How should i do for that. Thanks for any answer.
Upvotes: 16
Views: 26910
Reputation:
If you want to see where you have put your code, then you can use this one:
var_dump($this->db->database);
Upvotes: 0
Reputation: 1912
We can easily fetch the database details in codeigniter.
Just use below code and print this you will get all database related information:-
print_r($this->db);
You can use this like below:-
$this->db->database
$this->db->hostname
$this->db->username
$this->db->password
Upvotes: 4
Reputation: 864
it is enough to get the present(active) database in codeigniter
echo $this->db->database;
Upvotes: 4
Reputation: 15476
Just use the public variable from the Database Driver object?
$this->db->database;
Upvotes: 48
Reputation: 32721
One way is to add your config.
$config['mydbname'] ='mydatabasename';
And call it in your controller.
$mydb=$this->config->item('mydbname');
$data['mydb']=$mydb;
$this->load->view('myview',$data);// it is not a good idea to show it in view.
// use $this->dbutil->list_databases();
//Returns an array of database names:
$dbs = $this->dbutil->list_databases();
foreach ($dbs as $db)
{
echo $db;
}
Upvotes: 0