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.
You must use a query builder like db_select() in order to use db_like() on all supported database systems. Using db_like() with db_query() or db_query_range() is not supported.
For example, the following does a case-insensitive query for all rows whose name starts with $prefix:
$result = db_select('person', 'p') ->fields('p') ->condition('name', db_like($prefix) . '%', 'LIKE') ->execute() ->fetchAll();
Backslash is defined as escape character for LIKE patterns in DatabaseCondition::mapConditionOperator().
string $string: The string to escape.
string The escaped string.
as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call escapeLike() on it. For example, $injected_database->escapeLike($string);
\Drupal\Core\Database\Connection::escapeLike()
function db_like($string) { return Database::getConnection()->escapeLike($string); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!database.inc/function/db_like/8.1.x