我想将此转换为查询生成器表达式。
我尝试了很多,但我做不到。如果可以,请你帮助我

$connect = mysql_connect("localhost","root","") or die("not connecting");
    mysql_select_db("skykeey",$connect) or die("no db :'(");

    $find1 =mysql_query("SELECT Count(*) FROM `mosqueculturalliablee` WHERE `email` ='$this->username'",$connect);
    $count1=mysql_fetch_row($find1);


我自己将其转换为:

$find1 =Yii::app()->db->createCommand()
    ->select ('count(*) as num')
    ->from('mosqueculturalliablee')
    ->where('email=' . $this->username)
    ->queryScalar();


但它不起作用,我得到了mysql语法错误

我该怎么办?

最佳答案

您没有在查询中包含$this->username的引号。

 ->where("email='" . $this->username."'") //outputs where email='username'


作为改进,您应该改用PDO

->where("email=:email")
->queryScalar(array(':email'=>$this->username));

关于php - 转换为Yii查询生成器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20132864/

10-16 15:44