2

My code is this

db_con =Mysql.new('localhost', 'root', 'root', 'user')
obj = db_con.query("select * from users where id=1 limit 1")
title=obj.fetch_hash["title"]

it gives result but my title is in Russian language e.g(знак ударения, znak udareniya) it gives us

title =???? ????????, znak udareniya

in my db it stored ,знак ударения, znak udareniya

how can i solve this problem please suggest me

3
  • Have you got '# encoding: utf-8' at the beginning of your file? Commented Apr 12, 2013 at 7:40
  • if you use rails dbconsole select * users where id = 1, does the name show correctly? Commented Apr 12, 2013 at 7:51
  • Yes name is showing correctly Commented Apr 12, 2013 at 8:40

2 Answers 2

2

You use

 db_con =Mysql.new('localhost', 'root', 'root', 'user')
    db_con.query("set names utf8")
    obj = db_con.query("select * from users where id=1 limit 1")
    title=obj.fetch_hash["title"]

and i found original results

Sign up to request clarification or add additional context in comments.

Comments

0

Change your encoding in DB to utf8 or create a new db:

$ mysql -u USER -p
create database YOURDB_NAME_development CHARACTER SET utf8 COLLATE utf8_general_ci;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.