Only today I realized that in my PHP scripts I was missing:
mysql_set_charset('utf8');
All my tables are InnoDB, sorting is "utf8_unicode_ci", and all my VARCHAR columns are also "utf8_unicode_ci". I have mb_internal_encoding('UTF-8'); on my PHP scripts, and all my PHP files are encoded as UTF-8.
So, so far, every time I "INSERT" something with diacritics, for example:
mysql_query('INSERT INTO `table` SET `name`="Jáuò Iñe"');
The contents of 'name' will then be: Jáuò Iñe : Jáuò Iñe .
Since I fixed the encoding between PHP and MySQL, the new INSERTs are now stored correctly. However, I want to fix all the old lines that are currently "messed up." I already tried a lot, but it always breaks the lines into the first "illegal" character. Here is my current code:
$m = mysql_real_escape_string('¿<?php echo "¬<b>\'PHP á (á)ţăriîş </b>"; ?> ă-ţi abcdd;//;ñç´พดแทฝใจคçăâξβψδπλξξςαยนñ ;'); mysql_set_charset('utf8'); mysql_query('INSERT INTO `table` SET `name`="'.$m.'"'); mysql_set_charset('latin1'); mysql_query('INSERT INTO `table` SET `name`="'.$m.'"'); mysql_set_charset('utf8'); $result = mysql_iquery('SELECT * FROM `table`'); while ($row = mysql_fetch_assoc($result)) { $message = $row['name']; $message = mb_convert_encoding($message, 'ISO-8859-15', 'UTF-8'); //$message = iconv("UTF-8", "ISO-8859-1//IGNORE", $message); mysql_iquery('UPDATE `table` SET `name`="'.mysql_real_escape_string($message).'" WHERE `a1`="'.$row['a1'].'"'); }
"UPDATE" with the expected characters, except that the string is truncated after the character "ă". I mean that this character and the following characters are not included in the string.
Also, testing with "iconv ()" (which is commented out by the code) does the same, even with // IGNORE and // TRANSLIT
I also checked several encodings between ISO-8859-1 and ISO-8859-15.
I really need help here! Thank.
php mysql iso-8859-1
Nuno Peralta Feb 23 2018-12-12T00: 00Z
source share