How do I set table prefix in Yii

ajaybc picture ajaybc · May 18, 2012 · Viewed 13.5k times · Source

In a project I am working on I need to set a table prefix for the project which I can change later. Browsing through the docs I came across this : http://www.yiiframework.com/doc/api/1.1/CDbConnection#tablePrefix-detail

But it is not explained where I implement this. I mean should I put it in protected/config/main.php or edit the core files ?

Answer

DCoder picture DCoder · May 18, 2012

You put it in the config file, along with other db configuration, like this:

'db'=>array(
  'connectionString' => 'xxxxx',
  'username' => 'xxxxx',
  'password' => 'xxxxx',
  'tablePrefix' => 'tbl_',
),

All public properties of any component can be set in the config file this way.