开发者

mysql query in zend framework need some hint

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜