Heelo guys , i'm trying to retrieve a stored arabic information from my sql database , the data has arrived successfully , but not arabic , it came like that :
NON Arabic characters
any one can help ?
here is my code
we suppose database tables were set to a Latin-1
1-Export the data as Latin-1. Because MySQL knows that the table is already using a Latin-1 encoding, it will do a straight export of the data without trying to convert the data to another character set. If you try to export as UTF-8, MySQL appears to attempt to convert the (supposedly) Latin-1 data to UTF-8 – resulting in double encoded characters (since the data was actually already UTF-8).
2-Change the character set in the exported data file from ‘latin1’ to ‘utf8’. Since the dumped data was not converted during the export process, it’s actually UTF-8 encoded data.
3-Create your new table as UTF-8 If your CREATE TABLE command is in your SQL dump file, change the character set from ‘latin1’ to ‘utf8’.
4-Import your data normally. Since you’ve got UTF-8 encoded data in your dump file, the declared character set in the dump file is now UTF-8, and the table you’re importing into is UTF-8, everything will go smoothly.
Related
I had a mysql database in which I saved some special characters é , but in the database it was saved like this é, later on I realised that it is due to the encoding and I changed the encoding scheme for my table and DB to UTF-8 but the text already inserted in it didn't changed,
My question is
Is there a way to automatically change all the content to 'obey' UTF-8 .
Is there a way that I can alteast update é to é?
NOTE: I know about the update command , but I dont think that will help here with characters with in the field.
I had some similar problems.
You need to set the encoding to utf-8 in:
the html or php file
the database column
and the database connection
From what you have said you already set the encoding in the database column.
To change the database connection use mysqli_set_charset ($conn, 'UTF-8');
If all of these are set to UTF-8 the data should display correctly.
I am doing the folloiwing steps to import data into my e-commerce shop:
convert excel sheet to csv in excel
open csv file in notepad++ and convert to UTF-8
import csv file in phpmyadmin
If I look at the front end of the webpage the french characters are displayed as ?. The charset of the page is utf-8
If I change the charset to iso-8859-1 everything displays correctly.
If I check the item in the phpmyadmin the accents are displayed correctly.
How come utf-8 is not displaying them correctly? I thought it should display é etc.
If i go to the back end of the website and edit the product, the french description displays properly in the WYSIWYG editor. If I save then the product the french characters then show correctly. But this is because the WYSIWYG editor is converting the characters to html entities.
A common issue when collecting Unicode DATA is leaving the Connection and database/table/column character set configurad as ISO-8859-1, but then inserting data that is actually utf-8. The database is essentially told, "here's some 8859-1-encoded data, store it in this 8859-1 table". It doesn't do any conversions because it doesn't realize the data isn't in 8859-1. So the data is utf-8 but the database has essentially been told it's in 8859-1.
It's an insidious problem because, as you say, the database will convert them wrongly if you change your charset to UtF-8, since it will convert the "8859-1" data (remmember the databae thinks it's 8859-1) to utf-8 - a conversion that fails of course, as the data really is in utf-8.
So basically the problem is that phpmyadmin is in 8859-1 but you told it to insert the data in 8859-1 and then told it you were providing data in 8859-1, and then gave it utf-8 data. The database thinks it's 8859-1 so the only easy way to solve the problem is to a) keep acting like it's 8859-1 even though it's not, and hope you never have to deal with sorting, searching, collation, etc ( may work in your case), or b) pulling out the data as 8859-1 ( leaving it unconverted ), then re-inserting it after setting the database and connection to utf-8 so the database knows what character set the data really is in.
Hope that makes sense. Let me know if it doesn't. This is a hard one to wrap your head around.
You might consider opening your csv with PHP (since you mention it in your tags), and use utf8_encode on the fields before saving them with queries.
This question is so old, but changing the encoding of the file from ISO-8859-1 to UTF-8 in various programs such as Excel etc was not working for me.
My issue is words like intérêt shows up as intérêt in the file.
In case this helps someone, here is what finally worked for me:
Starting with a CSV file, open in Notepad
Click "File > Save As".
In the dialog window that appears - select "ANSI" from the "Encoding" field. Then click "Save".
That's it! Opening this new CSV file using Excel should now show the non-English characters properly.
I recenly had problem in importing latin1_swedish database into new one. Somone made Latin1 Database to store Latin2 characters. It was all working till I made database dump and wanted to import it to another database.
It's really complicated. In the end I corrected sql dump to proper ISO-8859-2 Encoded file with all characters displaying correctly. Still import into tables with Latin2 encoding didn't work, all special characters were lost (maybe its a PHPMyAdmin bug?).
Converting file to UTF-8 encoding and changing table encoding to utf8_general_ci imported everything correctly.
Next, whole PHP site uses and displays ISO-8859-2 characters (its old PHPBB forum).
While connecting to Database I use "SET NAMES latin2" command to change encoding.
To my surprise, page displays as proper ISO-8859-2.
If table is UTF-8 and Set names is latin2. Does MySQL connection convert characters into ISO-8859-2 before returning them???
(didnt know if I shoud write it all or not. Edit it if I put too much not needed info)
SET NAMES effectively sets how the data is translated before being stored or after recalled, prior to presenting to the client. For the case of storage, the character set definition of the column is the ultimate determining factor (if it differs from table, and database character set definition). See this informative blog post about encoding in MySQL.
I have a MySQL table & fields that are all set to UTF-8. The thing is, a previous PHP script, which was in charge of the database writing, was using some other encoding, not sure whether it is in the script itself, the MySQL connection or somewhere else. The result is that although the table & fields are set to UTF-8, we see the wrong chars instead of Chinese.
It looks like that:
Now, the previous scripts (which were in charge of the writing and corrupted the data) can read it well for some reason, but my new script which all encoded in UTF-8, shows chars like ½©. How can that be fixed?
By the sound of it, you have a utf8 column but you are writing to it and reading from it using a latin1 connection, so what is actually being stored in the table is mis-encoded. Your problem is that when you read from the table using a utf8 connection, you see the data that's actually stored there, which is why it looks wrong. You can fix the mis-encoded data in the table by converting to latin1, then back to utf8 via the binary character set (three steps in total).
The original database was in a Chinese encoding – GB-18030 or similar, not Latin-1 – and the bytes that make up these characters, when displayed in UTF-8, show up as a bunch of Latin diacritics. Read each string as GB-18030, convert it to UTF-8, and save.
the data im working with here is off of a page that uses utf8 encoding
i've set my database and fields to use utf8_general_ci
now for whatever reason, i have to use the following code on the variable in order to have it display accented characters correctly in the database:
mb_convert_encoding($name,'ISO-8859-15','utf-8');
this makes no sense to me. why do i have to convert it to ISO-8859-15 when phpmyadmin is in utf8, the data is in utf8, and the database and table fields are in utf8?
You most likely have not set your database connection to UTF-8, so your database expects you to send ISO-8859 encoded data. See http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html