Add database in codeigniter dynamically -


i working on codeigniter app allow user add edit , modify database.

i want repeat code loop:

$db['db1']['hostname'] = 'localhost'; $db['db1']['username'] = 'ts4l_wp13'; $db['db1']['password'] = 'o&3d6c(0zd70.^9'; $db['db1']['database'] = 'ts4l_wp13'; $db['db1']['dbdriver'] = 'mysql'; $db['db1']['dbprefix'] = ''; $db['db1']['pconnect'] = false; $db['db1']['db_debug'] = true; $db['db1']['cache_on'] = false; $db['db1']['cachedir'] = ''; $db['db1']['char_set'] = 'utf8'; $db['db1']['dbcollat'] = 'utf8_general_ci'; $db['db1']['swap_pre'] = ''; $db['db1']['autoinit'] = true; $db['db1']['stricton'] = false; 

i this:

@$get_data = mysql_query("select * `database_name`");     while($getdata =  mysql_fetch_assoc($get_data)){             $id='db'.$getdata['id'];     $iid="$id";                      $db["$iid"]['hostname'] = 'localhost';                      $db["$iid"]['username'] = $getdata['username'];                      $db["$iid"]['password'] = $getdata['password'];                      $db["$iid"]['database'] = $getdata['name'];                      $db["$iid"]['dbdriver'] = 'mysql';                      $db["$iid"]['dbprefix'] = '';                      $db["$iid"]['pconnect'] = false;                      $db["$iid"]['db_debug'] = true;                      $db["$iid"]['cache_on'] = false;                      $db["$iid"]['cachedir'] = '';                      $db["$iid"]['char_set'] = 'utf8';                      $db["$iid"]['dbcollat'] = 'utf8_general_ci';                      $db["$iid"]['swap_pre'] = '';                      $db["$iid"]['autoinit'] = true;                      $db["$iid"]['stricton'] = false;     } 

and block.

// loading  db , running query.         $ci = &get_instance();               $this->db1 = $ci->load->database('db1', true);         $this->db1->set($data);         $this->db1->insert($this->_table_name);         $id=$this->db1->insert_id(); 

i this:

$this->load->model('mdb_m');   $dbms =$this->mdb_m->get();          if (count($dbms)) {            foreach ($dbms $dbm) {               $mid=$dbm->id;               $dbc='db'.$mid;                $ci = &get_instance();                   $this->db.$mid = $ci->load->database( "$dbc" , true);                $this->db.$mid->set($data);                $this->db.$mid->insert($this->_table_name);            }         } 

but insert @ first database in array stop , retrive error "you have specified invalid database connection group."

you can brief information of using multiple database here.as have mentioned. https://ellislab.com/codeigniter/user-guide/database/connecting.html

for better approach can make loader file load database.i in same problem , got clear visualization here

https://coderwall.com/p/_kyjvg/codeigniter-loading-up-multiple-databases

refer here , if still confused please revert me thankyou.


Comments