Monday, September 28, 2009

db_query and LIKE %s

You need to use %% to create a literal %.

Example:

db_query('select x from {table} where x like "%%%s%"', $string);

Another way
nevets - October 9, 2006 - 03:56

If you define the thing you are search for like
$pattern = '%' . $somevalue . '%';

and do your query something like
$results = db_query("SELECT .... WHERE field LIKE '%s'", $pattern);

you get rid of the need for the pairs of % signs.

1 comment:

Unknown said...

I prefer the repair damage sql database application, developed by another company. I believe that it is the fastest way to open corrupted documents of specified format