Welcome Guest, Not a member yet? Register   Sign In
Changing username and password in database.php @ runtime
#1

[eluser]Unknown[/eluser]
I am new to codeigniter.
I want to change the username and password in databse.php

$db['default']['username'] = "";
$db['default']['password'] = "";

at runtime.
I have created library as HitDb in which i have written function as connection() which takes name of the database.Each database has different username and password, so to achieve this i want to change username and passsword in database.php.I attached library that i had wriiten also mentioned how i am calling to this function and what i have tried but not getting success.
Any help is appreciated.
Thankx in advance...!!
Code:
<?php
i am calling to connection function as

      $this->ProjDb     = & $this->hitdb->connection('project');
      $this->PurchaseDb = & $this->hitdb->connection('Purchase');

class Hitdb {
private $CI;
private $connectioncache = array();

        function Hitdb() {
  $this->CI =& get_instance();
                
}
        
function &connection;($name = 'default', $company = '', $starttransaction = false)
        {
  if($name != 'default' && $company == '')
                    $company = $this->CI->hitauth->companyid;
  if(isset($this->connectioncache[$company][$name]))
                     return $this->connectioncache[$company][$name];
  else
                {
                       include(APPPATH.'config/database'.EXT);
                      
                       require_once(BASEPATH.'database/DB_driver'.EXT);
                       $paras = $db['default'];
/*
I tried in this way but not getting result as expected                        
                      
                    $paras['username'] = $this->getDbUserName($name);            
                    $paras['password'] = $this->getDbPassword($name);

*/
     if($name != 'default')
                        $paras['database'] = '[' . $paras['database'] . '_' . $company . '_' . str_replace('-', '_', $name) . ']';
  
                    $this->connectioncache[$company][$name] =& $this->CI->load->database($paras, true);
      if($starttransaction)
                            $this->connectioncache[$company][$name]->trans_begin();
                        
      return $this->connectioncache[$company][$name];
  }
}
}
?>




Theme © iAndrew 2016 - Forum software by © MyBB