When is query successfull?

I am using the code below

	$sql61 = "select `direct` from ct  where `id` ='".$id."' and `sid` ='".$ud."'";

				$rows61 = Yii::app()->db->createCommand($sql61)->queryAll();


Now i would like to run certain code when the above query is successful(i.e. true I believe).

Will it be like this?

if($rows61){echo "Query succesful";}

You just need to check the documentation for the queryAll() function and see what is written there - http://www.yiiframework.com/doc/api/1.1/CActiveRecord#findAll-detail

$sql61 = "select `direct` from ct  where `id`=:id and `sid` =:ud";

$rows61 = Yii::app()->db->createCommand($sql61)->queryAll(true, array(':id' => $id, ':ud' => $ud));

if (false !== $rows61) {



Safer to pass in the params instead of concatenating the string.

use like below

$conn = $this->getDbConnection();

$query = 'SELECT Name from tab_name WHERE id ’ $cId;

$rows = $conn->createCommand($query)->queryRow();

return $rows[‘Name’];

IMHO most elegant solution is to use command builder functionality:

  $command = Yii::app()->db->createCommand();







  $row = $command->queryRow(true, array(':id'=>$id, ':sid'=>$sid));

  if ($row!==false) {

	echo "Query succesful";