Created
May 17, 2012 05:28
-
-
Save fukayatsu/2716668 to your computer and use it in GitHub Desktop.
MySQL接続サンプルのruby版
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql' | |
db = Mysql.connect('localhost', 'root', '', 'ca') | |
while(true) do | |
print "name(empty to exit) > "; name = gets.chomp | |
break if name == '' | |
print "password > "; password = gets.chomp | |
#prepared Statement | |
stmt = db.prepare('SELECT * FROM user WHERE name = ? AND password = ?') | |
count = 0; | |
stmt.execute(name, password).each do |id, name, tel, password| | |
count += 1; | |
puts "#{id}, #{name}, #{tel}, #{password} \n"; | |
end | |
if (count == 0) then | |
puts "Not Found. invalid name or password\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment