1

i am getting following error.

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

and this is my Db setting,now i am new to Yii so i dont know if there are some other things that i should mention, so if there are any other do let me know i will paste them ASAP.

// This is the configuration for yiic console application. // Any writable CConsoleApplication properties can be configured here.

return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'My Console Application',

    // preloading 'log' component
    'preload'=>array('log'),

    // application components
    'components'=>array(
//      'db'=>array(
//          'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
//      ),
        // uncomment the following to use a MySQL database

        'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=mydb',
            'emulatePrepare' => true,
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ),

        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, warning',
                ),
            ),
        ),
    ),
);
1
  • Do you have MySQL installed on your localhost? Is it running? (The file you posted is the configuration for running Yii in the console/command prompt. The configuration for the Yii web app is typically in main.php.) Commented Feb 15, 2014 at 14:55

2 Answers 2

1

I think you are missing the class:

'db'=>array(
            'class'=>'CDbConnection', // specify class 
            'connectionString' => 'mysql:host=localhost;dbname=mydb',
            'emulatePrepare' => true,
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ),
Sign up to request clarification or add additional context in comments.

2 Comments

Also where is your code placed? i believe its under protected/config/main.php
ah, i think i found what is missing that file is hitting some remote db all the time iw as looking for some other file named config.php
1

I think mysql server is not running on your machine or the server you use.

3 Comments

hmm, and how to test if i am running a remote server?
i am connected VIA Xammpp on local and other apps are running fine, but this isnt
I seems that mysql is not started on your localhost. I don't use XAMPP but I know it has a control panel where you can see all processes that are running or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.