蛋糕PHP API中的MySQL查询 [英] MySql query in cake php Api

查看:99
本文介绍了蛋糕PHP API中的MySQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于数据检索,我需要使用 binary 关键字在mysql
中进行区分大小写的搜索,这是我要进行的查询

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%'

这是我在cakephp中进行的查询,没有二进制文件

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

有1个可以帮助我使用Cakephp API进行二进制查询吗....

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

推荐答案

好的...您快到了。您只需要将Field放在方括号中,以告诉CakePHP不要将BINARY关键字作为字段名称处理

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

相信这应该可行:

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

这篇关于蛋糕PHP API中的MySQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆