CodeIgniter Forums
Change DB config - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: Change DB config (/showthread.php?tid=71309)



Change DB config - arber.smajli - 07-31-2018

Hi everyone,

I try to make a login to my DB (directly to the DB, not to a table containing users)

But I don't know how could I change the configuration in the default database

For example this could be the begining : 

PHP Code:
$db['default'] = array(
    
'dsn'    => '',
    
'hostname' => $tnsname,
    
'username' => '',
    
'password' => '',
    
'database' => '',
    
'dbdriver' => 'oci8',
    
'dbprefix' => ''

And then in the controller, change the $username and $passeword with variables so I can login.

Can anyone help me in this case ? any tips ?


RE: Change DB config - php_rocs - 07-31-2018

@arber.smajli,

You can have multiple database configurations. See documentation: https://www.codeigniter.com/user_guide/database/connecting.html?highlight=multiple%20database#connecting-to-multiple-databases


RE: Change DB config - arber.smajli - 08-01-2018

Thank you for your message

I see what you mean but it's not what I search.

I will try to explain you differently ;

I am making a database monitor, so to acces to the page, the admin have to connect to the database.

So, in first case, the database configuration (application/config/database.php) is empty.

And if the admin enter the correct username/passeword (of the database) he is loged on.

This is what I can't do for the moment, write in application/config/database.php from a controller.

So if anyone has an idea, it would be cool.


RE: Change DB config - InsiteFX - 08-02-2018

You can still use generic MySQLi to access your databases etc;


RE: Change DB config - arber.smajli - 08-02-2018

The thing is I use Oracle databases


RE: Change DB config - php_rocs - 08-02-2018

(08-01-2018, 11:42 PM)arber.smajli Wrote: Thank you for your message

I see what you mean but it's not what I search.

I will try to explain you differently ;

I am making a database monitor, so to acces to the page, the admin have to connect to the database.

So, in first case, the database configuration (application/config/database.php) is empty.

And if the admin enter the correct username/passeword (of the database) he is loged on.

This is what I can't do for the moment, write in application/config/database.php from a controller.

So if anyone has an idea, it would be cool.

I understand what you are saying.  There are many approaches that you an take.  I will give you two off the top of my head...
  1. You could create a library/script that will automatically update the config file adding the new connections details.  Also, the script should be able to remove them as well.
  2. You could create a library/script that will use the default PHP connection string and encypt and save the database login information as it is added by the user.
And I'm quite sure others may have other suggestions.