Chintan_chiku
Chintan_chiku

Reputation: 425

YII how to get number of rows affacted using queryRow Function

In YII, to get single row i m using queryRow function

$SQL = //SQL QUERY

$data = Yii::app()->db->createCommand($SQL);
$result = $data->queryRow();

print_r(count($result));

print_r always shows 1 even if no data-set returned by query. i want if no data-set is returned it should show 0. so can call some other function

what is the issue ?

Upvotes: 1

Views: 1160

Answers (1)

Pentium10
Pentium10

Reputation: 207922

queryRow returns boolean FALSE or the first row. There is no count to be done here.

$row = $data->queryRow();

if ($row!==FALSE) {
   echo "I have results";
   print_r($row);
} else {
   echo "I don't have results";
}

If you want to get all rows you need to use queryAll

Upvotes: 1

Related Questions