1

I am trying to set up a query with php and sqlite and the query has multiple LIKE conditions...

$findMe  = 'blah';
$nLast   = -1; 
$nRecord = 5;
$db      = new PDO('sqlite:data.db');
$qry = "SELECT *
        FROM mytable    
        WHERE (id > $nLast)     
        AND ((col1 LIKE '%$findMe%')    
        OR (col2 LIKE '%$findMe%')  
        OR (col3 LIKE '%$findMe%')  
        OR (col4 LIKE '%$findMe%'))     
        LIMIT $nRecord  
        ORDER BY id DESC";
$result = $db->query($qry);

...but this will not return any results. if i run the query with just one of the LIKE conditions it will work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
jayveesea
  • 23
  • 4

1 Answers1

1

Why not try using glob instead of like?

select *
from "mytable"
where ('col1' || 'col2' || 'col3' || 'col4')
glob '%$findMe%'
Rogue
  • 11,105
  • 5
  • 45
  • 71
  • Is their any documentation available about the glob keyword? I am asking because I cannot find any information about it when searching the internet. – SharpKnight Sep 24 '13 at 17:00
  • 1
    A quick search revealed this: http://www.tutorialspoint.com/sqlite/sqlite_glob_clause.htm – Rogue Sep 24 '13 at 17:04
  • i was avoiding GLOB because it is case-sensitive... that being said i tried your example and it does not work for me either. i am now wondering if i am using the parentheses correctly, can ANDs and ORs be isolated with parentheses? – jayveesea Sep 24 '13 at 19:37
  • @jayveesea As far as I know, ANDs and ORs can be isolated with parentheses. – SharpKnight Sep 26 '13 at 17:09