wailynnoo
wailynnoo

Reputation: 349

To grab codeigniter database name

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

Answers (5)

user12504414
user12504414

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

Deepak Dholiyan
Deepak Dholiyan

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

Raja Ram T
Raja Ram T

Reputation: 864

it is enough to get the present(active) database in codeigniter

 echo $this->db->database;  

Upvotes: 4

Repox
Repox

Reputation: 15476

Just use the public variable from the Database Driver object?

$this->db->database;

Upvotes: 48

shin
shin

Reputation: 32721

  1. 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. 

2.Use database utility class.

// use $this->dbutil->list_databases();

//Returns an array of database names:

$dbs = $this->dbutil->list_databases();

foreach ($dbs as $db)
{
    echo $db;
}

Upvotes: 0

Related Questions