1

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.

1
  • 1
    Just run apt-get install php5-mysql or apt-get install php7-mysql. Commented Dec 24, 2017 at 14:57

1 Answer 1

6

try to run php -me from the cli and make sure pdo_mysql is there.. if not, then u need to enable it from your php.ini config.

Sometime, when u use server stack such as lamp/xampp, u probably missed out from resync your environment path to use the same version of php.ini of your server stack. to do this, u may simply check/compare php.ini path from both phpinfo() from the browser and php -i from the cli

Sign up to request clarification or add additional context in comments.

2 Comments

Hi @kidzen I really liked your answer. I am having a hell with php versions and extensions. I just modified the path to use the same php v as wampp. when I run php -v it appears that I am running the same version, but its not seen the same extensions. Any idea?
Ho, thanks I found it, apparently, wampp uses two different php.ini files, one for the server and one for the php script. I made it work, thanks for the tip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.