bleu
(Zend W)
1
I am using the code below
$sql61 = "select `direct` from ct where `id` ='".$id."' and `sid` ='".$ud."'";
$rows61 = Yii::app()->db->createCommand($sql61)->queryAll();
$rowscont61=$rows61[0];
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";}
mdomba
(Maurizio Domba Cerin)
2
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
alex-w
(Pr0j3ct A1ex)
3
$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.
scspl.pravin
(Phpwebdeveloper900)
4
use like below
$conn = $this->getDbConnection();
$query = 'SELECT Name from tab_name WHERE id ’ $cId;
$rows = $conn->createCommand($query)->queryRow();
return $rows[‘Name’];
madand
(Dev Madand)
5
IMHO most elegant solution is to use command builder functionality:
$command = Yii::app()->db->createCommand();
$command->select('direct')->from('ct')
->where(array(
'and',
'id=:id',
'sid=:sid',
));
$row = $command->queryRow(true, array(':id'=>$id, ':sid'=>$sid));
if ($row!==false) {
echo "Query succesful";
}