A question about CPagination with DAO




	public function actionIndex()

	{

		$criteria=new CDbCriteria();

		$sql = 'SELECT subject,picture

			FROM cases

			ORDER BY createtime ASC';

				

		$query = Yii::app()->db->CreateCommand($sql);

		$res = $query->query();

		/*change to this now: $res = $query->queryAll(); */


		$pages=new CPagination($res->rowCount);

                /*change to this now: $pages=new CPagination(count($res));*/


		$pages->pageSize = 8;

		$pages->applyLimit($criteria);


		$query = Yii::app()->db->createCommand($sql.' LIMIT :offset,:limit');

			$query->bindValue(':offset',$pages->currentPage*$pages->pageSize);

			$query->bindValue(':limit', $pages->pageSize);

		

		$this->v['posts'] = $query->queryAll();

		$this->v['pages'] = $pages;	


		$this->title = 'Cases';

		$this->render($this->action->id,$this->v);		

	}



Hello,This is a action in the Controller,It’s Output error Words ‘Cannot execute queries while other unbuffered queries are active’ When run this program in Linux OS,How do i change this code?Please help me!

Partially untested…




	public function actionIndex()

	{


                $sqlCount = 'SELECT COUNT(*) as rows FROM cases';


		$sql = 'SELECT subject,picture FROM cases ORDER BY createtime ASC LIMIT :offset, :limit';

				

		

                $numberOfRecords = Yii::app()->db->CreateCommand($sqlCount)->queryScalar();


		$pages=new CPagination(intval($numberOfRecords));


		$pages->pageSize = 8;


		$query = Yii::app()->db->createCommand($sql.' LIMIT :offset,:limit');


		$query->bindParam(':offset',($pages->currentPage*$pages->pageSize), PDO::PARAM_INT);

		$query->bindParam(':limit', $pages->pageSize, PDO::PARAM_INT);

		

		$this->v['posts'] = $query->queryAll();

		$this->v['pages'] = $pages;	


		$this->title = 'Cases';

		$this->render($this->action->id,$this->v);		

	}



I wonder why dont you just create a Case Model instead, wouldnt be much easier?

Thank you very much!These Codes are very good.

My pleasure…