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.
Related
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.
When read a Excel file using Spreadsheet_Excel_Reader data contain unwanted � between each characters,When insert it into mysql DB. How to solve this issue
Sounds like a character set mismatch. This question on SO might help re. the spreadsheet: php-excel-reader - problem with UTF-8 and then check that your tables/columns are using the same (ideally UTF-8) character set, and that your connection is also using UTF-8.
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've developed an PHP/MySQL-application where in one table names are stored. These names sometimes contain special characters (like é, à, ë, ...).
When creating the table I had forgotten to set the collocation-item to UTF-8 and now is set to LATIN1_SWEDISH_CI.
So some data isn't displayed correct in phpMyAdmin. But when I show the names on a PHP-page, those special characters are displayed correctly. Here's an extract from a PHP-file where I use UTF-8
<?php ... ?>
<html>
<head>
<meta http-equiv="Content-Type" content-"text/html; charset="UTF-8">
....
Like I said the special characters are displayed as it should. So far... no problem.
But now I would like to export that data into an CSV-file and guess what? The special characters aren't included in the CSV-file.
My PHP-export-file contains the following lines of code:
<?php
mysql_query("SET NAMES utf8");
header('Content-Type: text/html; charset=UTF-8');
...
But no special characters are displayed?
Does anyone have a solution for this problem? Because I find it a little ridiculous to open the CSV in Excel and use 'Find & Replace'.
Using the HTML escape-codes is out of the question. That's why there's UTF-8, not?
You have stored UTF-8 encoded data which MySQL regards as Latin-1 data. MySQL does not complain about this because any arbitrary sequence of bytes is valid Latin-1. Because the connection character set of the connection used to retrieve the data is the same as that used to insert it, the correct data is displayed on your web page. But if you view the data in a utility that takes pains to display the actually stored characters, you will see mis-encoded text, because that is what you actually have stored.
There are two things you need to do: firstly, you need to change your database connection code to make sure that all connections you make to your database are using the UTF-8 character set. This can be accomplished using a settings file or just by issuing a SET NAMES statement every time you connect.
Secondly, you need to correct the mis-encoded data already stored in the database. Do not alter table to change the character set to UTF-8 directly; if you do, you will end up with double-UTF-8-encoded data. Instead, use an alter table query to change the column to the binary character set, and after doing that, alter table again to UTF-8.
There is a MySQL database and I want to select columns from a table.
I must return a String from the concatenation of the selected column values. But in one of the columns there are accentuated letters in the column value , like é.
So how to encode the column returned value ?
NB : I already wrote header('Content-Type: text/plain; charset=utf-8'); at the beginning of the PHP file.
Defining charset with SET NAMES 'utf-8' may help.
http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html
What encoding is your database table in? On a lot of installations, MySQL defaults to LATIN-1. Make sure the table stores its data as UTF-8, then make sure that the connection between MySQL and PHP is in UTF-8. The easy way to do that is running the query SET NAMES utf8 after connecting, but you can also set a default encoding.
Next, the UTF-8 header should be sent from the server to the browser, but you've already done that by adding the header() call.
If your database table is currently not encoded as UTF-8, you might need to re-enter your data after changing it.
Maybe the Multibyte String Module can be of some help to you, part of the Human Language and Character Encoding Support.