Jump to content
Larry Ullman's Book Forums

Yii Model Generator - Can Not Connect To Database


Recommended Posts

Barely installed Yii and already ran into trouble.

I'm running Windows 7 and use Wamp and MySQL for my database.

After installation, I went to the url http://localhost/myproject/index.php?r=gii and selected Model Generator.

I've edited both main.php and console.php in C:\wamp\www\myproject\protected\config folder to include the following:


            'connectionString' => 'mysql:host=localhost;dbname=myproject',
            'emulatePrepare' => true,
            'username' => 'myproject',
            'password' => 'thepassword',
            'charset' => 'utf8',


However, when trying to preview the model, the first field "Database Connection" gives me the following error:

"A valid database connection is required to run this generator."


I had the previous line in comments, and now tried changing into:

            'connectionString' => 'mysql',

Although it did not help.


I've tried googling around and people have had similar problems, but editing both of the files solved their problems. For some reason it won't work for me. Is 'localhost' all I need to point it to wamp and phpMyAdmin?


Can you help?

Link to comment
Share on other sites

The joy of answering my own thread!


I had written the database's name in the "Database Connection" field. It was not necessary, however, I should have just let it be the default value 'db'. Glad it worked now! :)

Link to comment
Share on other sites


  • Create New...