Skip to content

Instantly share code, notes, and snippets.

@fukayatsu
Created May 17, 2012 05:28
Show Gist options
  • Save fukayatsu/2716668 to your computer and use it in GitHub Desktop.
Save fukayatsu/2716668 to your computer and use it in GitHub Desktop.
MySQL接続サンプルのruby版
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