Problem with ConsoleApplication

I follow this instructions to make a new console application http://www.yiiframew.../topics.console

I supposed that I could use the defined models and use it to search information and made the things that I needed to do. But I got the following exception:


 exception 'CDbException' with message 'CDbConnection.connectionString cannot be empty.

Stack trace:

#0 /home/diego/public_html/yii-1.1.0.r1700/framework/db/CDbConnection.php(237): CDbConnection->open()

#1 /home/diego/public_html/yii-1.1.0.r1700/framework/db/CDbConnection.php(216): CDbConnection->setActive(true)

#2 /home/diego/public_html/yii-1.1.0.r1700/framework/base/CModule.php(357): CDbConnection->init()

#3 /home/diego/public_html/yii-1.1.0.r1700/framework/base/CApplication.php(391): CModule->getComponent('db')

#4 /home/diego/public_html/yii-1.1.0.r1700/framework/db/ar/CActiveRecord.php(526): CApplication->getDb()

#5 /home/diego/public_html/yii-1.1.0.r1700/framework/db/ar/CActiveRecord.php(1929): CActiveRecord->getDbConnection()

#6 /home/diego/public_html/yii-1.1.0.r1700/framework/db/ar/CActiveRecord.php(328): CActiveRecordMetaData->__construct(Object(Puesto))

#7 /home/diego/public_html/rh/protected/models/Puesto.php(23): CActiveRecord::model('Puesto')

#8 /home/diego/public_html/rh/protected/commands/cumplesCommand.php(21): Puesto::model()

#9 /home/diego/public_html/yii-1.1.0.r1700/framework/console/CConsoleCommandRunner.php(62): cumplesCommand->run(Array)

#10 /home/diego/public_html/yii-1.1.0.r1700/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)

#11 /home/diego/public_html/yii-1.1.0.r1700/framework/base/CApplication.php(135): CConsoleApplication->processRequest()

#12 /home/diego/public_html/yii-1.1.0.r1700/framework/yiic.php(31): CApplication->run()

#13 /home/diego/public_html/rh/protected/yiic.php(7): require_once('/home/diego/pub...')

#14 /home/diego/public_html/rh/protected/yiic(4): require_once('/home/diego/pub...')



Anyone want to help me?

First line of the exception says it as clean as possible


connectionString cannot be empty

That means in


your_project_di/protected/config/main.php

undert the


'db'=>...

You have an empty connection string. If you still issue this problem cp/paste this part of your confing/main.php

I have the following the config/main.php


'db'=>array(

                        'connectionString' => 'mysql:host=localhost;dbname=rh',

                        'emulatePrepare' => true,

                        'username' => 'diego',

                        'password' => '********',

                        'charset' => 'utf8',

                ),

That isn’t empty.

In protected folder root. I have the command which import the config file. The code of the command is the following:


<?php

defined('YII_DEBUG') or define('YII_DEBUG',true);

// include Yii bootstrap file

require_once('../../yii-1.1.0.r1700/framework/yii.php');

// create application instance and run

$configFile='config/main.php';


Yii::createConsoleApplication($configFile)->run();

?>

Could be that the command didnt read sucessfully the config file(main.php) but the path is correct…

Maybe the path is mistaken.

Try using $config=dirname(FILE).’/config/console.php’;

or main.php. This is how yiic command find the configuration.

Thanks man.

I missed the db configuration in the config/console.php


'components'=>array('db'=>array(

                        'connectionString' => 'mysql:host=localhost;dbname=******',

                        'emulatePrepare' => true,

                        'username' => '*****',

                        'password' => '*****',

                        'charset' => 'utf8',

                ),

        )