CDbCache怎么用啊?
有人用过没有啊,我按Yii文档里面说的写了写,
可是不能成功啊!我用的是MySql数据库,
那个CDbCache已经在我的数据库里面生成了Yiicache表了,
可就是当我缓存数据的时候,提示我数据库不是活动的!
貌似不能插入数据库记录,我晕了!
在英文论坛模块里面发了个帖子,没人回!
我想可能是我英文太差了!
所以还是寄希望于天朝子民了!
CDbCache怎么用啊?
有人用过没有啊,我按Yii文档里面说的写了写,
可是不能成功啊!我用的是MySql数据库,
那个CDbCache已经在我的数据库里面生成了Yiicache表了,
可就是当我缓存数据的时候,提示我数据库不是活动的!
貌似不能插入数据库记录,我晕了!
在英文论坛模块里面发了个帖子,没人回!
我想可能是我英文太差了!
所以还是寄希望于天朝子民了!
你的main.php是怎样的?
‘db’=>array(
'connectionString' => 'mysql:host=localhost;dbname=test',
'emulatePrepare' => true,
'username' => 'root',
'autoConnect'=>true,
'password' => '123',
'charset' => 'utf8',
),
‘cache1’=>array(
'class'=>'system.caching.CDbCache',
'connectionID'=>'db',
//'autoCreateCacheTable'=>false,
//'cacheTableName'=>'yiicache',
),
‘cache2’=>array(
'class'=>'system.caching.CMemCache',
'servers'=>array(
array('host'=>'localhost', 'port'=>11211, 'weight'=>60),
),
),
代码每次运行到:Yii::app()->cache1->set("persons",$persons,60);
就会报错!错误如下:CDbConnection is inactive and cannot perform any DB operations.
public function createCommand($sql)
{
if($this->getActive())
return new CDbCommand($this,$sql);
else
throw new CDbException(Yii::t('yii','CDbConnection is inactive and cannot perform any DB operations.'));
}
我不明白这是怎么回事?既然CDbCache在我数据库里面生成了yiicache表了,应该就没有问题的啊!
<_<
在执行Yii::app()->cache1->set("persons",$persons,60);之前看看Yii::app()->db->active的值是true还是false?
OK,successful!Thank you qiang!