Get the count of records from a table .
The best of way of retrieving the count of a query in yii.
For all record
$sql = "SELECT COUNT(*) FROM tablename;
$numRecordsFound = Yii::app()->db->createCommand($sql)->queryScalar();
For Criteria Based record.
$sql = "SELECT COUNT(*) FROM tablename where columnName=".$columnValue;
$numRecordsFound = Yii::app()->db->createCommand($sql)->queryScalar();
No comments:
Post a Comment