1

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

$select = $this->select ()
               ->where ( "phone =  '" . $post ['phone'] . "'")
               ->where(!( "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

2 Answers 2

5

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:

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, one question per post.
Just follow the instructions. If the question doesn't meet the quality standards, you should get a hint about what's wrong. Maybe it's not explicit enough. Remember to elaborate on your questions, giving as much detail as possible. In this case you'll want to describe the desired effect, your current code and what's wrong with it. It should do fine.
2

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.

7 Comments

You sure about the validator name in the last line of your code? ;)
Db_NoRecordExistPhone there. It is an invented name. You will have to write you and the Validator by the name you want!
Why? There's a standard validator anyway, why write another one that does exactly the same thing?
Why do you want to check that there is the same phone without taking into account member_id, while the standardized validator only checks whether or not in the database and present value of the phone. Not so?
Nope. If you only take into account the key pair: phone + uid, you don't need a check at all. There's only one user record for a given user ID anyway. You'd just run an update and forget any validation at all. The OP asks for validation, so it's rather obvious to me he doesn't want two users with the same phone number. Correct me if I'm wrong. Anyways, even if your reasoning were true, the standard validator can check multiple columns as well.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.