Read/insert Chinese data from mysql database saved by php code
NickName:Grant Chen Ask DateTime:2014-06-29T15:10:33

Read/insert Chinese data from mysql database saved by php code

I want to use ruby to read/insert data to a mysql database, onto which data were saved by a php code. When I read Chinese data, it does not appear correctly. It appears like 刘佳. But in a php page, it shows Chinese data correctly as 刘佳.

I confirmed the database uses utf-8 charset (CHARSET=utf8 COLLATE=utf8_unicode_ci).

my ruby code

require 'active_record'

class Student < ActiveRecord::Base
end

ActiveRecord::Base.establish_connection(
  adapter:  'mysql2',
  host:     'xxxx',
  username: 'xxxx',
  password: 'xxxx',
  database: 'xxx_db',
  encoding: 'utf8'
)

puts Student.first.name

It outputs an unknown string "刘佳".

How can I read Chinese data correctly and save a new Chinese record to database?

Copyright Notice:Content Author:「Grant Chen」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24473907/read-insert-chinese-data-from-mysql-database-saved-by-php-code

More about “Read/insert Chinese data from mysql database saved by php code” related questions

Read/insert Chinese data from mysql database saved by php code

I want to use ruby to read/insert data to a mysql database, onto which data were saved by a php code. When I read Chinese data, it does not appear correctly. It appears like 刘佳. But in a php pa...

Show Detail

php odbc insert chinese data not accurate

I am trying to insert chinese data which is stored in variable got from $_POST data on a form. so after submitting the form containing the chinese data, it was stored into a variable in this way $

Show Detail

chinese character in mysql insert and phpmyadmin

i have this chinese character which i want to insert into database and browser output in correct but when data is inserted into mysql it is in different format something like this. my chinese char...

Show Detail

Insert Chinese characters in MySql database using Java

In my local environment it works fine, in my production environment, it doesn't. I've been reading a lot of answers on the internet. It seems I didn't get the answer I'm looking for. I can read C...

Show Detail

insert chinese character into mysql through php and vba

I tried still cannot input the Chinese character into the field.. The url looks like this: http://xxx.xxx/AddCategory.php?CatID=0001&amp;NameTC=石油&amp;NameEN=Petroleum%20Gases&amp;Random=1.401764E...

Show Detail

MySQL database unrecognize chinese characters extracted from Excel file (xls)

I try to extract data (Chinese Charaters) from excel(.xls), but when inserted, the database does not recognize the characters (appear blank and symbols). Please help me to solve the problems. &lt...

Show Detail

PHP MYsql Query Chinese Character

PHP MYsql Query Chinese Character I did the following My database was set to UTF-8 I also did the code SET NAMES 'UTF8'; SET CHARACTER SET 'UTF8'; My sql was able draw the data out from

Show Detail

php code to insert row of data populated from a mysql database into other mysql database after modification

I am trying to make an attendance sheet. In my code I retrieve the names from a existing database and populate in a html table with the attendance select dropdown. After populating the dropdown all...

Show Detail

PHP Chinese Characters Can't Insert To Mysql

I am using GET to pass parameters, succesful save data to mysql if the data is in english, but nothing insert if the data is in chinese. I have detected the data encoding is utf-8, found out that ...

Show Detail

read from mysql database,why chinese character can read by this

Mysql is default set,all character_encoding is 'latin1',I have rightly store the chinese content.My programe is UTF-8 encode.But when i read from mysql,I only succeed read chinese content through as

Show Detail