ruby 查询mysql输出乱码,求解
RT.求解决方法,谢谢。
# encoding: utf-8require 'mysql'conn = Mysql.real_connect("127.0.0.1", "root", "123456")conn.query('USE test;')conn.query('set names utf8;');db = conn.query("SELECT * FROM admin_role;")while row = db.fetch_row() do puts row[1]end
[ STDIN, STDOUT, STDERR ].each do |stdio| stdio.set_encoding(Encoding.locale_charmap, 'utf-8')end
[解决办法]
conn.query('set names gbk;'); #is that right ?