「Ruby」の版間の差分
提供: sha.ngri.la
細 (→MySQLを使う) |
細 (→MySQLを使う) |
||
18行目: | 18行目: | ||
sql = "select * from tablename" | sql = "select * from tablename" | ||
rs = db.query sql | rs = db.query sql | ||
− | rs.each do | | + | rs.each do |columns| |
− | id = | + | id = columns[0] |
− | nam = | + | nam = columns[2] |
− | email = | + | email = columns[3] |
end | end | ||
end | end |
2013年5月5日 (日) 13:40時点における版
MySQLを使う
$ gem install mysql
id | name | |
---|---|---|
1 | foo baa | baa@***.com |
2 | ofo abaa | abaa@***.com |
3 | oof aab | aab@***.net |
fooo.rb
require 'mysql' begin db = Mysql::connect('localhost','username','password','database') sql = "select * from tablename" rs = db.query sql rs.each do |columns| id = columns[0] nam = columns[2] email = columns[3] end end