Ruby & MySQL

require "rubygems"
require 'mysql'

db = Mysql.connect('localhost', 'root','******','ruby')

db.query("insert into people values(null,'卡夫',22)")

begin
	query = db.query('select * from people')
	puts "There were #{query.num_rows} rows returned"
	
	query.each_hash do |h|
		puts h.inspect
	end
rescue
	puts db.errno
	puts db.error
end
db.close
 

你可能感兴趣的:(mysql)