Database Exception – yii\db\Exception


I’m new to Yii, and just now I’m studying “The Definitive Guide to Yii 2.0”, Working with Databases Chapter

I’ve created yii2basic database, db.php with the following content:


return [

     'class' => 'yii\db\Connection',

     'dsn' => 'mysql:host=;dbname=yii2basic',

     'username' => 'root',

     'password' => '',

     'charset' => 'utf8',


I have also created Country.php and CountryController.php , as described in the Guide, but, when I try to follow the link <MY_HOST_NAME>/frontend/web/index.php?r=country/index I get the following error:

[spoiler]Database Exception – yii\db\Exception

SQLSTATE[28000] [1045] Access denied for user ‘root’@‘localhost’ (using password: NO)

Caused by: PDOException

SQLSTATE[28000] [1045] Access denied for user ‘root’@‘localhost’ (using password: NO)

in /home/<LOCAL_PATH>/Projects/www/yii/vendor/yiisoft/yii2/db/Connection.php at line 579


The example from the previous Chapter of the Guide works pretty fine, and so do Apache and MySQL. I can enter the latter using my root password.

So, what I’m doing wrong?

OS: Linux Mint 17

Yii Version: 2.0.3

PHP Version: 5.5.9-1ubuntu4.7

Apache Version: Apache/2.4.7 (Ubuntu)

MySQL Client API version: 5.5.41

Are you sure your mysql have no password ? Maybe you should try ‘root’ as password.

You can also try ‘localhost’ instead of ‘’ in dsn host.

The problem was, I used advanced version of Yii2, not basic, and as I remember, there is no point in the Guide, that you must use the basic verison. With basic version everything works as described in the Guide. Configuration of advanced version is somewhat different.