我有一个SQL查询,无法弄清楚如何在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
}
我尝试过以下方式,无法弄清楚我的错误
$cmd1 = Yii::app()->db->createCommand("select * from tbl where cmail='$mail' and ename='$ename' ");
$cmd1->execute();
if(mysqli_num_rows($cmd1)>0)
{
//...
}
else
{
//...
}
答案 0 :(得分:0)
$results = Yii::app()->db
->createCommand("select * from tbl where cmail='$mail' and ename='$ename'")
->queyAll();