尝试通过gii创建模型时出现Yii错误

时间:2016-10-15 15:19:46

标签: php yii2

尝试通过Gii创建模型时出错。我正在访问此地址http://hostname/index.php?r=gii并出现此错误

Database Exception – yii\db\Exception

SQLSTATE[HY000] [1049] Unknown database 'yii2basic'
↵
Caused by: PDOException

SQLSTATE[HY000] [1049] Unknown database 'yii2basic'

in W:\XAMPP\htdocs\basic\vendor\yiisoft\yii2\db\Connection.php at line 602

1 个答案:

答案 0 :(得分:1)

您应该在db.php配置文件中分配正确的值

在你的basic \ config目录中找到文件\ db.php,然后为数据库分配正确的值,用户名和密码

return [
   'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=yii2basic',
                                           ^^^ assign your correct dbname
    'username' => 'root',  // assign you  correct username  
     'password' => '',     // assign your password 
    'charset' => 'utf8',
 ];