If you have done the tutorial on How to quickly create base yii app. This is a kind of next step.

Once a webapp is created it has no connection to a database. To get the app connected to a database you must provide all the necessary information inside the config file.


Let’s examine a bit the folder structure of your Yii webapp.

You shall find the config file inside the protected/config/ folder.

The file is called main.php.

Inside that file you’ll find the db parameter inside the application components array (basically, the place where yii loads all the components you will use to make the app work).

You can see that, as a start, the mysql declaration is greyed out. Decide which database you want to use ! Here goes the code for three of them:Oracle, mysql, SqLite.



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


			'connectionString' => 'mysql:host=localhost;dbname=testdrive',
			'emulatePrepare' => true,
			'username' => 'root',
			'password' => '',
			'charset' => 'utf8',


                'username' => ###',
                'password' => '####',

Notice that, for Oracle, the charset declaration is part of the connectionString.

If you go to your webapp inside your webbrowser you won’t see anything changed. At least you have no error !

Next time we will use Gii, the scaffolding tool of Yii.