0

for data retrieval i need to use binary keyword for case sensitive search in mysql this is the query i want to make

    SELECT username FROM users 
WHERE  BINARY first_name LIKE 'eph%'
OR     BINARY last_name LIKE 'eph%'
OR      BINARY username LIKE 'eph%'

and this is the query i have made in cakephp without binary

$this->User->find('list', array(
            'fields' => array('User.username'),
            'conditions' => array("OR" => 
                            array("BINARY User.last_name LIKE" => $search_data."%","BINARY User.username LIKE" => $search_data."%",
                                    "BINARY User.first_name LIKE" => $search_data."%"))
                                            ));

can any 1 help me out making the binary query using cakephp api ....

1 Answer 1

3

Ok ... you were almost there. You only need to put the Field in a bracket to tell CakePHP not to deal with the BINARY keyword as a field name

Believe this should work:

$this->User->find('list', array(
        'fields' => array('User.username'),
        'conditions' => array(
                       "OR" =>array(
                                "BINARY (`User`.`last_name`) LIKE" => $search_data."%",
                                "BINARY (`User`.`username`) LIKE" => $search_data."%",        
                                "BINARY (`User`.`first_name`) LIKE" => $search_data."%"))
                           ));
Sign up to request clarification or add additional context in comments.

1 Comment

In my case (Cake 2.3), I also had to remove the space after BINARY, so Cake wouldn't escape the word.

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.