db_like

  1. drupal
    1. 8
    2. 7
Versions
8 – 7 db_like($string)

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:

<?php
$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

▾ 17 functions call db_like()

comment_form_validate in modules/comment/comment.module
Validate comment form submissions.
DatabaseBasicSyntaxTestCase::testLikeBackslash in modules/simpletest/tests/database_test.test
Test LIKE query containing a backslash.
DatabaseBasicSyntaxTestCase::testLikeEscape in modules/simpletest/tests/database_test.test
Test escaping of LIKE wildcards.
DrupalDatabaseCache::clear in includes/cache.inc
Expire data from the cache. If called without arguments, expirable entries will be cleared from the cache_page and cache_block bins.
EntityFieldQuery::addCondition in includes/entity.inc
Adds a condition to an already built SelectQuery (internal function).
profile_admin_settings_autocomplete in modules/profile/profile.admin.inc
Retrieve a pipe delimited string of autocomplete suggestions for profile categories
profile_autocomplete in modules/profile/profile.pages.inc
Callback to allow autocomplete of profile text fields.
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.
taxonomy_autocomplete in modules/taxonomy/taxonomy.pages.inc
Helper function for autocompletion
user_account_form_validate in modules/user/user.module
Form validation handler for user_account_form().
user_autocomplete in modules/user/user.pages.inc
Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing users.
user_is_blocked in modules/user/user.module
Checks for usernames blocked by user administration.
user_search_execute in modules/user/user.module
Implements hook_search_execute().
user_update_7017 in modules/user/user.install
Update email templates to use new tokens.
_locale_translate_seek in includes/locale.inc
Perform a string search and display results in a table
_profile_get_fields in modules/profile/profile.module

Code

includes/database/database.inc, line 2579

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