function DatabaseConnection_mysql::quoteIdentifier

Quotes an identifier if it matches a MySQL reserved keyword.

Parameters

string $identifier: The field to check.

Return value

string The identifier, quoted if it matches a MySQL reserved keyword.

2 calls to DatabaseConnection_mysql::quoteIdentifier()
DatabaseConnection_mysql::escapeAlias in includes/database/mysql/database.inc
Escapes an alias name string.
DatabaseConnection_mysql::escapeField in includes/database/mysql/database.inc
Escapes a field name string.

File

includes/database/mysql/database.inc, line 444

Class

DatabaseConnection_mysql

Code

private function quoteIdentifier($identifier) {
    // Quote identifiers so that MySQL reserved words like 'function' can be
    // used as column names. Sometimes the 'table.column_name' format is passed
    // in. For example, menu_load_links() adds a condition on "ml.menu_name".
    if (strpos($identifier, '.') !== FALSE) {
        list($table, $identifier) = explode('.', $identifier, 2);
    }
    if (in_array(strtolower($identifier), $this->reservedKeyWords, TRUE)) {
        // Quote the string for MySQL reserved keywords.
        $quote_char = variable_get('mysql_identifier_quote_character', MYSQL_IDENTIFIER_QUOTE_CHARACTER_DEFAULT);
        $identifier = $quote_char . $identifier . $quote_char;
    }
    return isset($table) ? $table . '.' . $identifier : $identifier;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.