Answer the question
In order to leave comments, you need to log in
How to create a cache dependency for a given sample?
There is a table containing the parameters and their values.
So for the model I form a connection
public function getDbConnection() {
$params = Site::model()->findAll(array('select'=>'param_name,value','limit'=>'4'));
$conStr = 'mysql:host=';
foreach($params as $p) {
switch($p[param_name]) {
case 'mysql_host': $conStr .= $p[value].';dbname='; break;
case 'mysql_dbname': $conStr .= $p[value]; break;
case 'mysql_user': $username = $p[value]; break;
case 'mysql_pass': $password = $p[value]; break;
}
}
$connect = new CDbConnection($conStr,$username,$password);
return $connect;
}
Answer the question
In order to leave comments, you need to log in
Is it really worth storing the connection parameters to the MySQL database in the same database? It seems to me that doing so is not entirely correct - because it looks very clumsy. Or is it still describes the settings for connecting to another database?
If the task is to store the parameters in the database, then I would add a couple of fields:
- the time the parameter was changed (this way it will be possible to remember the last change in the parameters and cache according to it)
- group the parameters somehow logically - for example, create another entity "Parameter Group", and create a group_id field in your table. Then you can extract the parameters you need not 'limit'=>'4' but group_id = ?.
ps And in general it is necessary to proceed from the task. It seems to me that you came up with not the most correct solution to some problem, and now you are asking how to deal with it.
Tell me WHAT you are trying to solve with this code, because there may be a better solution
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question