# UTF8 Database content

**URL:** <https://www.ruby-forum.com/t/utf8-database-content/83099>\
**Category:** Rails I18n\
**Created:** [January 23, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/utf8-database-content/83099 "2007-01-23T18:01:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alkhater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@alkhater](https://www.ruby-forum.com/u/alkhater)\
**Post date:** [January 23, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/utf8-database-content/83099/1 "2007-01-23T18:01:32Z")

</div>

Hi,

Forgive me if this is a basic question. I am using rails and simply  
trying to get content stored and retrieved from the database in UTF8 (i  
am using arabic). When the data is stored it ends up as ???  
question marks. I have set the database charset and the table to UTF8.

Any help appreciated.

Abdulaziz

---

<div class="post-metadata">

**Author:** ![alkhater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@alkhater](https://www.ruby-forum.com/u/alkhater)\
**Post date:** [February 5, 2007, 8:41pm UTC](https://www.ruby-forum.com/t/utf8-database-content/83099/2 "2007-02-05T20:41:35Z")

</div>

> Forgive me if this is a basic question. I am using rails and simply  
> trying to get content stored and retrieved from the database in UTF8 (i  
> am using arabic). When the data is stored it ends up as ???  
> question marks. I have set the database charset and the table to UTF8.

This should interest you.

[http://woss.name/2006/10/25/migrating-your-rails-application-to-unicode/](http://woss.name/2006/10/25/migrating-your-rails-application-to-unicode/)

---

<div class="post-metadata">

**Author:** ![alkhater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@alkhater](https://www.ruby-forum.com/u/alkhater)\
**Post date:** [February 6, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/utf8-database-content/83099/3 "2007-02-06T14:25:58Z")

</div>

I just ran into similar problems Abdulaziz. I wrote an import script  
that imports data from files into the database. The problem was that  
the files were in one encoding (windows-1252) and the database in utf8.

I used the ‘iconv’ library which is available in standard Ruby to  
convert the file to utf8 first before attempting to put the data into my  
models and save them to the database. (On Windows I believe iconv is  
only available in the One-Click installer version of Ruby).

If it is MySQL at least, you can make sure Rails is talking to the  
database correctly by adding the “encoding” line to database.yml like  
this:

development:  
adapter: mysql  
database: adatabase  
encoding: utf8  
username: auser  
password: apassword  
host: localhost

(Be sure to restart Rails after adding this)

If the data is coming from the browser then you need to make sure the  
data is being sent correctly. If you are using MySQL you should also  
think about installing PHPMyAdmin and checking with that that the data  
is being stored properly, as it might just be a display problem.

Also make sure that any templates of pages being sent out to the browser  
have the line:

in the and that it is the very first entry.

Hope this helps and good luck.

Chad.
