require 'rubygems' require 'mysql' db = Mysql.connect('localhost','root','','book') db.query("insert into bookinfos (bookname,type) values('soft','2')"); begin query = db.query('select * from bookinfos') 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