Could someone tell me that how to connect MySQL with Ruby? I have XAMPP server installed and want to connect with ruby.
I am using Ruby1.8.7.
I tried following code:
require ‘rubygems’
require ‘mysql’
begin
dbh.close if dbh
end
OUTPUT: C:/xampp/htdocs/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require’: no such file to load – mysql (LoadError)
from C:/xampp/htdocs/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require’
from ruby_dbconnect.rb:4
I suggest you look at the Rails Guides, start with Getting Started,
obviously, and work through some Rails tutorials railstutorial.org is
good and free to use online. Make sure you use Rails 3 and that any
tutorials you try are for Rails 3
You're probably going to get more takers on the ruby-talk list, rather than rails-talk. We're all very busy with our integrated framework, rather than trying to build a connection to a database with stone knives and bear skins. (kidding about that!)
You've got a database handle (dbh). Before you close it in your script, use it to issue a SQL command to the server, like this:
res = dbh.query("SELECT name, category FROM animal")
while row = res.fetch_hash do
printf "%s, %s\n", row["name"], row["category"]
end