Wednesday, March 23, 2005

ruby musings

mysqlextension.rb - stored in /usr/lib/ruby/1.8/

require "mysql"

def older_people
query("SELECT * FROM people WHERE age>45")
end

def younger_people
query("SELECT * FROM people WHERE age<45")
end
end

mysqltest.rb:

# because mysqlextension.rb is in /usr/lib/ruby/1.8 its easily found by ruby
require "mysqlextension"
m=Mysql.real_connect( connection stuff )

#now here's the killer:

res=m.older_people

#so now i can do

while row=res.fetch_row do
print row[2], row[3]
end


why's that a killer? - well, yeah , you could do something similar with php, but the ruby way just feels kinda more elegant. lots more to read up on this. early days yet.