Yii版本为1.6
下面是控制器中的一段代码
public function actionList() { $tempPage = isset( $_GET['page'] ) ? (int)$_GET['page'] : 1; $tempSign = isset( $_GET['sign'] ) ? trim( $_GET['sign'] ) : $this->sign; $this->sign = $tempSign; //从缓存中提取新闻分类 $tempData = NewsClass::getInfoBySign( $this->sign ); $this->setSeoTitle( $tempData['seo_title']."_页{$tempPage}" ); $this->setSeoKeyword( $tempData['seo_keywords'] ); $this->setSeoDescription( $tempData['seo_description'] ); $objNews = new News(); //构造条件 $tempAryCondition = array(); $tempAryCondition['news_ncid'] = array($tempData['nc_id']); $criteria = new CDbCriteria(); $criteria->select = 'news_id,news_title,created_dt'; $criteria->condition = News::getFormatFrontCondition( $tempAryCondition ); $criteria->order = 'news_order asc , created_dt desc'; $pages = new CPagination( $objNews->count( $criteria ) ); $pages->pageSize = self::PAGE_SIZE; $pages->applyLimit( $criteria ); $newsList = $objNews->findAll( $criteria ); $tempAryParams = array(); $tempAryParams['newsclass'] = $tempData; $tempAryParams['newsList'] = $newsList; $tempAryParams['pages'] = $pages; $this->render( 'index' , $tempAryParams ); }
日志如下
2009/07/03 15:29:52 [trace] [system.db.CDbConnection] Opening DB connection 2009/07/03 15:29:52 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `info_news` 2009/07/03 15:29:52 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `info_news` 2009/07/03 15:29:52 [trace] [system.db.ar.CActiveRecord] News.count() 2009/07/03 15:29:52 [trace] [system.db.CDbCommand] Querying SQL: SELECT COUNT(*) FROM `info_news` WHERE delete_flg=0 AND news_status = 1 AND news_ncid IN (1) ORDER BY news_order asc , created_dt desc 2009/07/03 15:29:52 [trace] [system.db.ar.CActiveRecord] News.findAll() 2009/07/03 15:29:52 [trace] [system.db.CDbCommand] Querying SQL: SELECT news_id,news_title,created_dt FROM `info_news` WHERE delete_flg=0 AND news_status = 1 AND news_ncid IN (1) ORDER BY news_order asc , created_dt desc LIMIT 10 2009/07/03 15:29:52 [trace] [system.db.CDbConnection] Opening DB connection 2009/07/03 15:29:52 [trace] [system.db.CDbCommand] Querying SQL: SHOW COLUMNS FROM `info_news` 2009/07/03 15:29:52 [trace] [system.db.CDbCommand] Querying SQL: SHOW CREATE TABLE `info_news` 2009/07/03 15:29:52 [trace] [system.db.ar.CActiveRecord] News.count() 2009/07/03 15:29:52 [trace] [system.db.CDbCommand] Querying SQL: SELECT COUNT(*) FROM `info_news` WHERE delete_flg=0 AND news_status = 1 AND news_ncid IN () ORDER BY news_order asc , created_dt desc 2009/07/03 15:29:52 [error] [system.db.CDbCommand] Error in querying SQL: SELECT COUNT(*) FROM `info_news` WHERE delete_flg=0 AND news_status = 1 AND news_ncid IN () ORDER BY news_order asc , created_dt desc
日志配置中 'levels'=>'trace,info,error,warning',
这段代码进行了两次查询 count和findAll,日志中记录的查询却有四次,而且最后一条还是error
不知是怎么回事.
但是日志中出现了重复的查询记录,而且其中一条日志为error