2.8.4.4.3. Configure database connection in Yii 2

Attention!

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

Database connection details in Yii 2 are specified in the database configuration file:

  • If you are using the config/db.php file, you need to modify the following lines:
    'dsn' => 'mysql:host=хост;dbname=database',
    'username' => 'login',
    'password' => 'password',
    'charset' => 'utf8',
  • If you are using the file config/db_config.php, you need to modify the following lines:
    define('DB_HOST','host');
    define('DB_NAME','database');
    define('DB_USER_NAME','username');
    define('DB_PASSWORD','password');

Changes can be made using the file manager or any FTP client.

Content