demo application problems

Hi,

I’m new with PHP and Yii and I was trying to rub Model and CRUD generator from Yii demo application. In both cases I get this:





CDbException


CDbConnection.connectionString cannot be empty.


/Applications/MAMP/htdocs/YiiRoot/framework/gii/generators/crud/CrudCode.php(44)


32         ));

33     }

34 

35     public function requiredTemplates()

36     {

37         return array(

38             'controller.php',

39         );

40     }

41 

42     public function init()

43     {

44         if(Yii::app()->db===null)

45             throw new CHttpException(500,'An active "db" connection is required to run this generator.');

46         parent::init();

47     }

48 

49     public function successMessage()

50     {

51         $link=CHtml::link('try it now', Yii::app()->createUrl($this->controller), array('target'=>'_blank'));

52         return "The controller has been generated successfully. You may $link.";

53     }

54 

55     public function validateModel($attribute,$params)

56     {




THis demo came with latest stable version. I have check content of connectionString and it matches the real data, like port, database name. Database is started and accessible with phpadmin. What could be wrong?

Could you post the ‘db’ part of your /config/main.php file please? Other things to check are:

the login details are correct, and you can log in to your database with exactly the same credentials as you have in main.php

The ‘db’ settings are actually pointing to use MySQL (the default is sqlite)

Sure, here is actually the complete components array:





	'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		// uncomment the following to enable URLs in path-format

		/*

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		*/

		

		/*

		'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),

		

		*/

		// uncomment the following to use a MySQL database

	+

		'db'=>array(

//		'connectionString' => 'mysql:host=127.0.0.1;dbname=trackstar_dev;port=8889;',

			'connectionString' => 'mysql:host=127.0.0.1;dbname=yii_tour;port=8889;',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => 'root',

			'charset' => 'utf8',

		),


		'errorHandler'=>array(

			// use 'site/error' action to display errors

            'errorAction'=>'site/error',

        ),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),



OK - If you open up "Terminal" from /Applications/Utilities and type in


mysql -uroot -proot -h127.0.0.1 -P8889

do you get a connection error?

Nope.

Does it work if you comment out the db part for mysql, and uncomment the part for sqlite? Trying to work out if it’s an error with your config file, as this error should only appear when no connectionString has been specified.