开发者

mysql query in zend framework need some hint

开发者 https://www.devze.com 2023-03-13 14:36 出处:网络
i have an query in mysql zend framwork is there any other way of writing this $select = $this->select ()

i have an query in mysql zend framwork is there any other way of writing this

$select = $this->select ()
               ->where ( "phone =  '" . $post ['phone'] . "'")
               ->w开发者_Go百科here(!( "member_id != '" .$post['member_id'] . "'"));

what am trying to do is update phone no of member and see if the phone no already exist in datbase any other way of doing this can someone answer


First off, your code has a security issue. Always use safe quoting:

->where("phone = ?",$post["phone"])

As for the question, you can use the Zend_Validate_Db_NoRecordExists validator on your form. Here are some useful links:

  • http://framework.zend.com/manual/en/zend.validate.set.html#zend.validate.Db
  • http://framework.zend.com/issues/browse/ZF-8012

The idea of using this validator is precisely checking whether a given value doesn't already exist in the database, without any additional work on your queries.


To do this I suggest you use a validator on the form!

Example Form:

        //phone
    $this->addElement('text', 'phone',
                      array('label' => 'Phone', 'required' => true));
    $params = array(
        'table' => 'User',
        'field' => 'phone',
    );
    $this->phone->addValidator('Db_NoRecordExistPhone', false, array($params));

validator write in the query that will return the control should be true or false.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号