1 database.inc | private DatabaseConnection_mysql::quoteIdentifier($identifier) |
Quotes an identifier with backticks for MySQL 8 compatibility.
Not all identifiers need quotes, only keywords, but we add them on all fields and table names for consistency and to ease compatibility in the future.
Parameters
string $identifier: The field to check.
Return value
string: The identifier, quoted with backticks.
File
- core/
includes/ database/ mysql/ database.inc, line 174 - Database interface code for MySQL database servers.
Class
- DatabaseConnection_mysql
- MySQL database connection driver.
Code
private function quoteIdentifier($identifier) {
// Some identifiers are empty, such as when doing expressions.
if (strlen($identifier) === 0) {
return $identifier;
}
// Identifiers that have both a table and field should quote both.
elseif (strpos($identifier, '.') !== FALSE) {
list($table, $identifier) = explode('.', $identifier, 2);
return "`$table`" . '.' . "`$identifier`";
}
// Otherwise quote just the field name.
return "`$identifier`";
}