如何插入ö/ä/ü;在数据库中使用php utf8

如何插入ö/ä/ü;在数据库中使用php utf8,php,mysql,sql,database,utf-8,Php,Mysql,Sql,Database,Utf 8,我知道,有人问了十几次,但我唯一想做的就是使用php脚本在数据库中插入一个类似“Ä”的德语字母,这在现有的解决方案中根本不起作用 <?php header('Content-type: text/html; charset=utf-8'); $con = mysqli_connect("localhost", "username", "password"); mysqli_set_charset($con, "utf8mb4"); mysqli_select_db($con, "dat

我知道,有人问了十几次,但我唯一想做的就是使用php脚本在数据库中插入一个类似“Ä”的德语字母,这在现有的解决方案中根本不起作用

<?php
header('Content-type: text/html; charset=utf-8'); 
$con = mysqli_connect("localhost", "username", "password");

mysqli_set_charset($con, "utf8mb4");
mysqli_select_db($con, "database");
mysqli_query($con, "SET SESSION CHARACTER_SET_RESULTS =utf8mb4;");
mysqli_query($con, "SET SESSION CHARACTER_SET_CLIENT =utf8mb4;");
mysqli_query($con, "SET NAMES 'utf8mb4';");

mysqli_query($con,
"SET character_set_results = 'utf8',
character_set_client = 'utf8',
character_set_connection = 'utf8',
character_set_database = 'utf8',
character_set_server = 'utf8';");

$title = 'Ö';
$result = mysqli_query($con, 
"INSERT INTO Test (Title)
VALUES ('" . utf8_encode($title) . "');");
#Doesn't work, this was inserted: Ã
?>

如前所述,我必须删除utf8_encode()函数,这会使字符设置混乱。删除它后,它将尽可能平滑地工作。

mysqli\u query($con,“SET SESSION CHARACTER\u SET\u RESULTS=latin1;”;mysqli_query($con,“SET SESSION CHARACTER_SET_CLIENT=latin1;”)应为utf8mb4,而不是拉丁语1。请确保数据源正在提交UTF8。如果你没有指定你的网页是UTF8,它可能会在Windows-1252check phpMyAdmin中提交。在你的表格设置中,可能你需要切换表格的字符集谢谢你的快速回答,我检查了表格的字符集,它设置为UTF8\u general\u ci。我不知道如何确保提交数据的源是UTF8,但我将头字符集添加到utf-8。我还把拉丁文改成了uft8mb4。但问题是它仍然不起作用。还有其他想法吗?如果删除utf8\U编码?