我有一個joomla數據庫,其中mySQL連接歸類爲utf8_general_ci。 我在數據庫中有一些額外的數據表(與joomla安裝無關),我想從PHP腳本中填充數據。在數據庫中插入特殊字符php
以後編輯:檢查以下
當我試圖插入特殊字符(語言和區域特定的字符)我得到jibberish在數據庫中,像îăîșE>代替îăîşţ。
在的Joomla數據庫中的所有列的排序規則是:utf8mb4_unicode_ci(如果這有什麼差別)
奇怪的是,如果我表現出的數據庫的內容以電子郵件/移動應用(基於瀏覽器)它正確顯示數據。但是我可以看到,從PHP插入valus是不對的,因爲如果我從phpmyadmin面板手動插入它,該值將正確顯示在表中。
<?php header('Content-type: text/html; charset=UTF-8'); //header is specified here
$value_to_insert = addslashes($_REQUEST['value']); //get the value from the parameter
inserttask($value_to_insert); //insert the value into the datatable
function inserttask($value_to_insert)
{
$con = mysqli_connect("host",username,password,database); //set up my mysqli connection
//mysql_set_charset('utf8'); //this didn't help
if (!$con)
{
die();
}
$sql = "INSERT INTO `table` (`value`) VALUES ('".mysqli_real_escape_string($con, $value_to_insert)."')";
if($result=mysqli_query($con,$sql))
{
print "OK";
}
else
{
print "ERROR";
}
}
?>
任何想法如何插入此應該作出,使其兼容任何地區的依賴和字符?
後來編輯: 我跑了 「LIKE '%歸類%' 顯示變量」 collation_connection是 - utf8_general_ci collation_database查看 - latin1_swedish_ci collation_server的 - latin1_swedish_ci
難道這是問題嗎?
你有沒有試過'mysql_set_charset('utf8mb4'); '? – GertG
是的。如果我執行以下操作:mysqli_set_charset('utf8');打印$ con> character_set_name();它將打印出「Latin1」而不是utf8 – Laureant