How can special characters like ä, ö, ü be properly stored in a PHP MySQL database?

Special characters like ä, ö, ü should be properly stored in a PHP MySQL database by ensuring that the database, table, and column collation is set to a UTF-8 character set, such as utf8mb4_unicode_ci. Additionally, when connecting to the database using PHP, make sure to set the connection charset to UTF-8 to ensure proper handling of special characters.

// Set the connection charset to UTF-8
$mysqli = new mysqli("localhost", "username", "password", "database");
$mysqli->set_charset("utf8");

// Ensure database, table, and column collation is set to UTF-8
// Example SQL query to set collation for a table
$mysqli->query("ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");