Chapter 4, DbTest failed!

Hi, all

I am new to this framework, I have been following this book to get me started. However, I have run into this problem in Chapter 4 when I tried to test my database connection.

Output from the console:

There was 1 error:

1) DbTest::testConnection

CDbException: CDbConnection failed to open the DB connection.









Tests: 1, Assertions: 0, Errors: 1.

I strictly followed the steps in the book, and I tried both main.php and test.php, they both did not work as expected. Can anyone help me? I am driving crazy…

Note: Even if I use the default sqllite configuration, when I changed the name of the .db file, it still passed the test! What on earth is going on here???

can you post the entire main.php in config folder?


I have also been struggling with this same problem for a while now.

I’ve read through similar post: CDbException: CDbConnection failed to open the DB connection (both pages) and still am no closer to the solution.

Any help with this matter would be greatly appreciated!

The main.php file is as follows:


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(



	// preloading 'log' component


	// autoloading model and component classes






		// uncomment the following to enable the Gii tool




			'password'=>'Enter Your Password Here',

		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.





	// application components



			// enable cookie-based authentication



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














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






			'connectionString' => 'mysql:host=localhost;port=3306;dbname=trackstar_dev',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => 'root',

			'charset' => 'utf8',




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








					'levels'=>'error, warning',


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









	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']


		// this is used in contact page




Replying to my own post as today I found the solution as posted by (Alan Cheung - post 17) at CDbException: CDbConnection failed to open the DB connection resolved the problem.

Here is the code:







Thanks Alan!!