1 year ago

#73247

test-img

nativemash

Yii2 Exception 'yii\db\Exception' with message 'could not find driver' when running yii command

I am running my application local using Laragon and using mysql database and it works fine. However, when I run the command php yii, it gives me this error:

Exception 'yii\db\Exception' with message 'could not find driver'

in C:\laragon\www\project_name\vendor\yiisoft\yii2\db\Connection.php:647

Caused by: Exception 'PDOException' with message 'could not find driver'

in C:\laragon\www\project_name\vendor\yiisoft\yii2\db\Connection.php:721

I've looked through other solutions here like checking my php.ini file and making sure the extension pdo_mysql is enabled. I tried running phpinfo() and it says has pdo_mysql enabled. I've checked my extensions on Laragon (Menu->PHP->Extensions) and it is enabled as well.

I also run php -me and these are my output:

[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
Phar
readline
Reflection
session
SimpleXML
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

My db.php configuration:

<?php

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=127.0.0.1;dbname=xxx',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
    'tablePrefix' => 'fbz_',
];

I've tried everything but I still keep getting the error. Any help is appreciated.

php

yii2

0 Answers

Your Answer

Accepted video resources