I have an advanced yii2 template. I'm trying to create a console command. I've created a controller class and action incide console/controllers folder:
namespace console\controllers;
use yii\console\Controller;
class WorkModelController extends Controller
{
public function actionValidate(){}
}
My action should connect with mysql database, select some data and do something with it. When I running the command: yii work-model/validate I get this error:
C:\OSPanel\domains\localhost>yii work-model/validate Exception 'yii\db\Exception' with message 'could not find driver'
in C:\OSPanel\domains\localhost\vendor\yiisoft\yii2\db\Connection.php:56
My console/config/main.php and main-local.php files contain next db-config:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=dbname',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
];
When I trying connect to the database from another part of app all works fine, but when I trying connect from console I get this error.
Please, help me slove this error.
apt-get install php5-mysqlorapt-get install php7-mysql.