Airship\Engine\Database::escapeIdentifier PHP Méthode

escapeIdentifier() public méthode

Make sure only valid characters make it in column/table names
public escapeIdentifier ( string $string, boolean $quote = true ) : string
$string string - table or column name
$quote boolean - certain SQLs escape column names (i.e. mysql with `backticks`)
Résultat string
    public function escapeIdentifier(string $string, bool $quote = true) : string
    {
        $str = \preg_replace('/[^0-9a-zA-Z_]/', '', $string);
        // The first character cannot be [0-9]:
        if (\preg_match('/^[0-9]/', $str)) {
            throw new DBAlert\InvalidIdentifier(\trk('error.database.invalid_identifier', $string));
        }
        if ($quote) {
            switch ($this->dbengine) {
                case 'mssql':
                    return '[' . $str . ']';
                case 'mysql':
                    return '`' . $str . '`';
                default:
                    return '"' . $str . '"';
            }
        }
        return $str;
    }