I am trying to use the gii code generator to create models. I was able to access the gii code generator on my browser. However, when I click on the 'Model Genetator' I get the CDbException which says this 'DbConnection failed to open the DB connection: SQLSTATE[HY000] [14] unable to open database file'. Any one able to help me out with this? I am just getting started that's why I don't have enough reputation to upload photos.
open your protected/main.php file
find this and put database name and password there
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=yii',
'username' => 'rootnew',
'password' => '',
if you have not created database go to phpmyadmin and create database.
What Yii version are you using? If you are using Yii 1.1.16 go to your webroot / protected / config / database.php You will find what kamlesh.bar said
'class'=>'CDbConnection',
'connectionString'=>'mysql:host=localhost;dbname={DATABASE}',
'username' => '{DBUSER}',
'password' => '{DBPASSWORD}',
'emulatePrepare'=>true, // needed by some MySQL installations
In Yii 2 you have to edit the db.php file and edit:
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname={DATABASE}',
'username' => '{DBUSER}',
'password' => '{DBPASSWORD}',
'charset' => 'utf8',
];
I wish this solve your problem
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.