Question

I have a sql query and unable to figure out how to write it in yii

$con=mysqli_connect('localhost','user','pwd','db_name');
$check = mysqli_query($con,"select * from tbl where cmail='$mail' and ename='$ename' ");
if(mysqli_num_rows($check)>0)
{
   //do nothing;
}
else
{ 
   //insert row to db
}

I have tried doing it in the following way, unable to figure out my mistake

$cmd1 = Yii::app()->db->createCommand("select * from tbl where cmail='$mail' and      ename='$ename' ");
$cmd1->execute();
if(mysqli_num_rows($cmd1)>0)
{
//...
}
else
{
 //...
}
Was it helpful?

Solution

$results = Yii::app()->db
    ->createCommand("select * from tbl where cmail='$mail' and ename='$ename'")
    ->queyAll();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top