Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Ami

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:

 

'db'=>array(
            '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:

'db'=>array(
            '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?

Share this post


Link to post
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! :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...