Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ivymasterman's avatar

How to target letters with "Umlaut" in SQL query?

How can I specifically target the umlaut letters? Currently, the database ignores the umlaut completely: ö is treated as o, ...

If I type "böse", it returns "böse" and "bose". That is not what I want, only "böse" should be returned.

I have tried changing the database config, specifically the 'charset' and 'collation' attributes. I have set them to :

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => false,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

but that yielded no success. Also tried appending this statement to my query:

$query->query("CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL")

but nothing. Umlauts are still ignored. Any help pls

0 likes
5 replies
Muetze's avatar

I have never had any problems with umlauts or emojis with Laravel. And also never changed the database settings.

Is utf8mb4_unicode_ci available in the database and how is the data passed?

click's avatar

Try WHERE BINARY name = "böse".

$yourSearchValue = "böse";

YourModel::whereRaw("BINARY `your_column_name` = ?", [ $yourSearchValue ])->get();

This also works if you want case sensitive searching

ivymasterman's avatar
ivymasterman
OP
Best Answer
Level 3

I made this modification in "config/database.php" file:

'charset' => 'utf8',
'collation' => 'utf8_german2_ci',

and also made this alteration in the DB directly, manually, or via query:

DB::query("ALTER TABLE `" . env("DB_DATABASE") . "`.`" . $tableName. "` convert to character SET utf8 COLLATE utf8_german2_ci");

This did the trick.

peterpan26's avatar

try putting just one apostrophe behind the name . i dont know if it works but on excell if you put the letters MU , it changes them to UM and if you put 'MU and give it an enter it works. might be the same way here. as i said im not sure

Please or to participate in this conversation.