0

I can't believe it, but I'm not able to set the global character set in MariaDB to 'latin1_german1_ci' so that my database entries with German umlauts (two dots above a vowel) are displayed correctly.
In MySQL I had to replace #define MYSQL_DEFAULT_COLLATION_NAME 'latin1_swedish_ci' with #define MYSQL_DEFAULT_COLLATION_NAME 'latin1_german1_ci' in the configuration file config-win.h.
But in MariaDB I can't find this possibility, although I've googled for many hours.

phpMyAdmin displays the entries with German umlauts correctly, but the following code does not:

 <body>
  <?php
   $db_link = mysqli_connect('localhost', 'user', 'mypassword');
   mysqli_select_db($db_link, 'mydatabase');
   $db_query = 'SELECT * FROM myaddresses ORDER BY mylastname ASC';
   $db_result = mysqli_query($db_link, $db_query);
   $db_row = mysqli_fetch_array($db_result, MYSQLI_ASSOC);
   echo $db_row['mylastname'];
   mysqli_close($db_link);
  ?>
 </body>
</html> 

How resp. where can I configure the global character set in MariaDB?

Seeky
  • 78
  • 1
  • 9
  • Try `$mysqli->set_charset('utf8');` (See https://www.php.net/manual/de/mysqli.construct.php#refsect1-mysqli.construct-examples). Not a pro, but im using PDO init commands and i set `SET CHARSET 'utf8'` and `NAMES 'utf8'` - works for me. (EDIT: you need to set this right after the connection is made) – cottton Nov 14 '21 at 21:58
  • 1
    You don't need to recompile it to change collation. What character set/collation is defined on `lastname` (edit question to include `show create table myaddresses`). The collation `latin1_german1_ci` needs to map the character set -> look at `SHOW COLLATION LIKE '%german%';`. [character_set_server/collation_server](https://mariadb.com/kb/en/setting-character-sets-and-collations/#server-level) can be set globally. – danblack Nov 14 '21 at 22:04
  • Great, many thanks. This hint solved my problem: I had to change ```character-set-server = utf8``` to ```character-set-server = latin1``` in the file ```C:\Program Files\MariaDB\data\my.ini```. – Seeky Nov 15 '21 at 00:12
  • Please stop using the deprecated `utf8` charset. Use `utf8mb4` – Dharman Nov 15 '21 at 09:39
  • Please stop using that 10 year old functional database code. Use a library, or at least PDO. – miken32 Nov 15 '21 at 16:48

0 Answers0