Welcome Guest, Not a member yet? Register   Sign In
How can I change DB settings while the App is running
#1
Question 

Hello Everyone,

I want to change the default database settings while the application is running.
 
I define as

PHP Code:
config('Database')->default['hostname'] = $this->DBHost;
config('Database')->default['username'] = $this->DBName;
config('Database')->default['password'] = $this->DBUser;
config('Database')->default['database'] = $this->DBPass

in App/Libraries/Company.php

How i use?

I define it

PHP Code:
$this->COMPANY = new Company();
$this->SETTINGS = new Settings(); 

in BaseController. I'm getting this error.

Quote:CodeIgniter\Database\Exceptions\DatabaseException #8
Unable to connect to the database.
Main connection [MySQLi]: Access denied for user '****'@localhost (using password: YES)

If used like this:


PHP Code:
config('Database')->default['hostname'] = 'localhost';
config('Database')->default['username'] = 'my_username';
config('Database')->default['password'] = 'my_password';
config('Database')->default['database'] = 'my_database'

there is no problem

It gives an error when I define it in the library

How can i solve this?
Reply
#2

Are you sure that username and password are correct? Check DBUser and DBPass if you get correct values.
Reply
#3

He needs to set the MySQLi password.

Code:
// Shell from Control Panel or CMD - change your_password to yours.
cd mysql\bin
mysqladmin --user=root password "your_password"
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB