MySql query in cake php Api

天大地大妈咪最大 提交于 2020-01-06 06:53:07

问题


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:


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."%"))
                           ));


来源:https://stackoverflow.com/questions/12784767/mysql-query-in-cake-php-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!