yii之函数countBySql()

countBySql()源代码如下:

public function countBySql($sql,$params=array())
{
    Yii::trace(get_class($this).'.countBySql()','system.db.ar.CActiveRecord');
    return $this->getCommandBuilder()->createSqlCommand($sql,$params)->queryScalar();
} 
 

实际上countBySql()还是调用了CDbCommand::queryScalar,所以SQL的写法即为:

SELECT count(*) FROM * WHERE .....

以下写法错误:

select * from table1, table2 where ......
 

猜你喜欢

转载自hnlixf.iteye.com/blog/1672547