Ruby Mysql.real_connect
require 'rubygems'
require 'mysql'
def with_db
dbh = Mysql.real_connect('localhost', 'root', '', 'db_name', 3306, '/tmp/mysql.sock')
begin
yield dbh
ensure
dbh.close
end
end
with_db do |c|
c.query("set names utf8")
rs = c.query("select * from tb_name limit 1")
# puts rs.fetch_row
puts c.get_server_info
end
No comments :
Post a Comment