T
T
tincap2018-01-30 03:56:30
Yii
tincap, 2018-01-30 03:56:30

How to connect console Yii2 advanced to database?

Hello.
There is a database connection and it works in frontend and backend. But in console it refuses to run.
Where to configure the connection to the database in the console folder?
5a6fc2bc006e7475733835.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-01-30
@tincap

In main-local.php:

'db'     => [
    'class' => 'yii\db\Connection',
    'dsn'      => 'mysql:host=localhost;dbname=my_db',
    'username' => 'db_user',
    'password' => 'db_password',
//                'enableSchemaCache'   => true,
//                'schemaCacheDuration' => 3600,
//                'tablePrefix'         => '',
//                'charset'             => 'utf8mb4',
//                'enableQueryCache'    => true,
//                'queryCacheDuration'  => 600,
],

In a good way, the connection (if it is common for backend && frontend && console) should be moved to main-local.php in the folder common. And configure all configuration files in a folder environmentsand run php init.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question