Setting up database connection in Yii


The connection will not work with localhost. The host address must be taken from the data to connect to the database.

Credentials for connection to the database in Yii are specified in the application's configuration file. Depending on the structure of the configuration files, changes must be made in the file that contains the database settings:

  • In case of using a file protected/config/main.php you need to change the lines:
    'connectionString' => 'mysql:host=host;dbname=base_data',
    'username' => 'login',
    'password' => 'password',
  • In case the file contains protected/config/main.php for example, a similar line is indicated:

Then the changes must be made directly to the file specified in this line. In this example, this is /home/example/example.com/www/protected/data/filename.db.

Changes can be made using filemanager or any FTPclient.