My problem is that somehow I got databases in my databases like à, é, ê in regular format or utf8. After researching, I came to the conclusion that some browsers (I don’t know IE or FF or others) encode the presented input data, since there was no utf8 encoding intentionally added to handle submit forms. So, if I were reading data using utf8_encode, I would change other simple characters and vice versa.
My solution after studying the above solutions: 1. I created a new database with charset utf8 2. Imported the database AFTER I changed the definition of charset in the CREATE TABLE statement in the sql dump file from Latin ... to UTF8. 3. import data from the source database (for now, it may be quite simple to change the encoding to existing db and tables, and this is only if the source db is not utf8) 4. Update the contents of the database directly, replacing the characters encoded in utf8 in a simple format, for example
UPDATE `clients` SET `name` = REPLACE(`name`,"é",'é' ) WHERE `name` LIKE CONVERT( _latin1 '%é%' USING utf8 );
I put this line in the db class (for php code) to make sure this is a UTF8 message
$ this-> query ('SET CHARSET UTF8');
So ho upgrade? (step 4) I built an array with possible characters that can be encoded
$special_chars = array( 'ù','û','ü', 'ÿ', 'à','â','ä','å','æ', 'ç', 'é','è','ê','ë', 'ï','î', 'ô','','ö','ó','ø', 'ü');
I built an array with table pairs, the field needs to be updated
$where_to_look = array( array("table_name" , "field_name"), ..... );
than,
foreach($special_chars as $char) { foreach($where_to_look as $pair) { //$table = $pair[0]; $field = $pair[1] $sql = "SELECT id , `" . $pair[1] . "` FROM " .$pair[0] . " WHERE `" . $pair[1] . "` LIKE CONVERT( _latin1 '%" . $char . "%' USING utf8 );"; if($db->num_rows() > 0){ $sql1 = "UPDATE " . $pair[0] . " SET `" . $pair[1] . "` = REPLACE(`" . $pair[1] . "`,CONVERT( _latin1 '" . $char . "' USING utf8 ),'" . $char . "' ) WHERE `" . $pair[1] . "` LIKE CONVERT( _latin1 '%" . $char . "%' USING utf8 )"; $db1->query($sql1); } } }
The main idea is to use mysql coding functions to avoid coding between mysql, apache, browser and vice versa; NOTE. I did not have php functions available like mb _....
The best