问题
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