Stack Exchange
Number of rows of query - Yii
i want to get the number of rows returned by a query in Yii. This is my query : 
        $programsAlreadyExist = $connection->createCommand('
                SELECT *
                FROM `cat_programme` 
                WHERE `programme_code` = 513')
                ->queryAll();


The "COUNT" keyword should return a row containing the requested number. :-)
SELECT COUNT(*) FROM cat_programme WHERE programme_code = 513


Change the SELECT to:
SELECT count (*) FROM cat_programme WHERE programme_code = '513'

Thanks !!

You could also do if via the count() method
For ecample
$programsAlreadyExist = MyModel::find()
    ->where(['programme_code' => '513'])
    ->count();

