Is there any dynamic way to put sqlite database connection instead of using sqlite:f:\\wamp\\www\\qdr\\protected\\data\\testdrive.db in main.php
?
'db'=>array(
'connectionString'=>'sqlite:f:\\wamp\\www\\qdr\\protected\\data\\testdrive.db',
),
Sql lite is about a single file so you can keep it like this. No dynamic needed. I am sure you are using wamp. Just keep it like this. This is the best solution for you. When you move the project to live server then change accordingly. Sqlite is a single file so do not bother that much.
It depends on what you understand under the vague term dynamic. But you could for example create your custom DBConnection
class and override init()
there:
class DbConnection extends CDbConnection
{
public function init()
{
// Set $this->connectionString to whatever you want, maybe
// $this->connectionString = 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db';
parent::init();
}
}
You can use this component as db
component if you add
'class' => 'DbConnection',
to your main.php
.
Note, though, that the init()
method is only called the first time when the db
component is accessed. So whatever you set as connectionString
there will be used for the current request.