I have got a problem with accents and special characters such as: ñ, ç...
I use the following code to introduce data on a MySQL DB:
$artist = mb_convert_encoding(mb_convert_case($_POST["artist"], MB_CASE_TITLE), "UTF-8");
$title = mb_convert_encoding(mb_convert_case($_POST["title"], MB_CASE_TITLE), "UTF-8");
$name = mb_convert_encoding(mb_convert_case($_POST["name"], MB_CASE_TITLE), "UTF-8");
$query = $db->prepare("INSERT INTO songs (artist, title, name) VALUES (?, ?, ?)");
$query->execute(array($artist, $title, $name));
An example that fails (artist of the song / title of the song / ádam gracia). This is inserted as:
Artist Of The Song / Title Of The Song / Ãdam Gracia)
The worst of it is that locally (localhost), works perfectly, on my hosting, it gives the above output. The same happens with ç, ñ, etc..
I have tried changing encoding options at php my admin, but I don´t know what to do...
Thank you all!
尝试在连接中设置字符集,例如:
new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf-8", $dbUser, $dbPass);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.