2.8.4.4.3. Setting up a database connection in Yii 2

Attention!

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

Database connection data in Yii 2, the following are specified in the database settings configuration file:

  • In case of using a file config/db.php you need to change the lines:
    'dsn' => 'mysql:host=host;dbname=base_data',
    'username' => 'login',
    'password' => 'password',
    'charset' => 'utf8',
  • In case of using a file config/db_config.php you need to change the lines:
    define('DB_HOST','host');
    define('DB_NAME','база_data');
    define('DB_USER_NAME','login');
    define('DB_PASSWORD','password');

Changes can be made using filemanager or any FTPclient.

Content