You are here

function db_like in Drupal 7

Same name and namespace in other branches
  1. 8 core/includes/database.inc \db_like()

Escapes characters that work as wildcard characters in a LIKE pattern.

The wildcard characters "%" and "_" as well as backslash are prefixed with a backslash. Use this to do a search for a verbatim string without any wildcard behavior.

For example, the following does a case-insensitive query for all rows whose name starts with $prefix:

$result = db_query('SELECT * FROM person WHERE name LIKE :pattern', array(
  ':pattern' => db_like($prefix) . '%',
));

Backslash is defined as escape character for LIKE patterns in DatabaseCondition::mapConditionOperator().

Parameters

$string: The string to escape.

Return value

The escaped string.

Related topics

6 calls to db_like()
EntityFieldQuery::addCondition in includes/entity.inc
Adds a condition to an already built SelectQuery (internal function).
profile_browse in modules/profile/profile.pages.inc
Menu callback; display a list of user information.
TaxonomyTermController::buildQuery in modules/taxonomy/taxonomy.module
Builds the query to load the entity.
user_search_execute in modules/user/user.module
Implements hook_search_execute().
_locale_translate_seek in includes/locale.inc
Perform a string search and display results in a table

... See full list

File

includes/database/database.inc, line 2720
Core systems for the database layer.

Code

function db_like($string) {
  return Database::getConnection()
    ->escapeLike($string);
}