Phalcon查询返回扫描错误之前

时间:2019-01-21 09:44:47

标签: php phalcon

我正在使用phalcon框架,我想执行此查询

public function updateAction($id)
{
$email = $this->request->getPost('email');
 $check_email_unique = Users::find(['conditions' => 'id != ' .$id. ' AND email = '. $email]);

echo $check_email_unique->id;
return ;
    }

但是在测试时,邮递员上的函数返回错误

2 个答案:

答案 0 :(得分:2)

您希望绑定参数,因为您正在执行的操作容易受到SQL注入的攻击。<​​/ p>

尝试一下:

$check_email_unique = Users::findFirst([
    'conditions' => "email = :email: AND id != :id:",
    'bind' => [
        'email' => $email,
        'id' => $id
    ]
]);

答案 1 :(得分:0)

谢谢..我这样解决了我的问题:

    public function updateAction($id)
        {
        $email = $this->request->getPost('email');
        $check_email_unique = Users::findFirst(['conditions' => "email = '".$email."' AND id != '".$id."'"]);

    echo  $check_email_unique->id; 
return ;
    }