Hi,
I have recently been looking into using Yii, and have been very impressed with it. I have looked through the documentation, and am working my way through the blog tutorial. A question that struck me early on was how do I use the Yii database application component to access my database with the minimum permissions necessary for a particular operation.
Previously, I have always created at least two users in a database. One for read/write operations, and one for read only operations. In the context of the blog application, the read user would be used to display the posts, while the read/write user would be used to create/update/delete posts.
I realise that by using CDbConnection I could create two connections:
$conn_read=new CDbConnection($dsn,$username_r,$password_r);
$conn_write=new CDbConnection($dsn,$username_w,$password_w);
However, I was wondering if there is already a built-in option to do this using the application component? Something along the lines of:
'dbRead'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdb',
'emulatePrepare' => true,
'username' => 'db_read',
'password' => 'password',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
),
'dbWrite'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdb',
'emulatePrepare' => true,
'username' => 'db_write',
'password' => 'password',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
)
I am new to Yii, so may be missing something obvious, but it appears as though the default is to have just one all-powerful user for database connections.