0

In CakePhp, how MySQL Like works as case insensitive search. I have tried with following code but problem is also coming here.

If i am searching "Motel Park" then result is fine.

But when searching "motel park" no result is found.

In database Collation is latin1_swedish_ci

$where_condition = array('Ad.completed' => 1,
                         'Ad.address LIKE '=>'%'.$_REQUEST['address'].'%',
                         'Ad.status' =>$ad_status
                        );
 $result =  $this->Ad->find('all',array('conditions'=>$where_condition));
Naresh
  • 2,761
  • 10
  • 45
  • 78
  • 3
    You shouldn’t be using the `$_REQUEST` superglobal. CakePHP has `$this->request->data` for POST data, and `$this->request->query` for query string parameters. – Martin Bean May 01 '14 at 08:33

2 Answers2

2

You can convert both the value to lowercase to use LIKE statement

$where_condition = array(
    'Ad.completed' => 1,
   'LOWER(Ad.address) LIKE '=>'%'.strtolower($this->request->data['address']).'%',
    'Ad.status' =>$ad_status
  );
$result =  $this->Ad->find('all',array('conditions'=>$where_condition));
Rajeev Ranjan
  • 4,152
  • 3
  • 28
  • 41
1

try using "COLLATE utf_general_ci" collation. refer this link.

but there is an easy solution , by converting all string in to lowercase. then check.

$request_address=strtolower($_REQUEST['address']);
$where_condition = "Ad.completed =  1 AND
                    LOWER(Ad.address) LIKE '%".$request_address."%' AND
                    Ad.status ='".$ad_status."'";  

$result =  $this->Ad->find('all',array('conditions'=>$where_condition));
Community
  • 1
  • 1
Arka
  • 581
  • 5
  • 18