---
title: "Ruby Tips"
author: "jacky"
date: "2008-07-01T23:46:46Z"
tags: []
slug: "ruby-tips"
draft: false
lastmod: "2008-07-01T23:46:46Z"
id: 210346
url: "https://jacky.iteye.com/blog/210346"
---

1. Ruby DBI launch operation in Mysql with conditions as follow:
   
   a) The Character encoding of MYSQL table is UTF-8

   b) If the encoding of Ruby file is "UTF-8" without BOM, then we need to convert the Chinese character using
   
```ruby

   name="你好"
   name = Iconv.new("GBK", "UTF-8").iconv(name)
   sqlstr = "insert into test(name) values('#{name}')"
   dbh.execute(sqlstr)
   
```
   
   If IDE is using ANSI as default,then not need to convert the encoding.