Saturday, June 14, 2008

Ruby database access using mysql dbd.

Step 1: Install mysql driver for ruby.

You can download package from here

Execute: ruby extconf.rb --with-mysql-config

Then make;make install

Step 2: Write simple ruby client.
  require "mysql"
my = Mysql.connect("localhost", "", "", "test")
puts my
res = my.query("select * from tblMovies")
res.each do |row|
puts row[0]+row[1]
end

That's it! Now you can access a database with Ruby.

No comments: