I’m sorry to ask such a newbie question but I wasn’t able to figure
this out yet. I just want to write a simple Ruby program that can
select data from a MySql database. I assume that Ruby DBI would be the
easiest way to go but I don’t think I have the required modules/gems
installed. I can’t even do a require ‘dbi’, it throws the following
error: LoadError: no such file to load – dbi
I found a few tutorial pages but they don’t give all the steps. These
are the pages I used as reference:
Basically I am looking for the step-by-step instructions on how to run
a query on a MySql DB using a Ruby program from thin air. My system is
a Mac OSX Leopard with ruby 1.8.6 (2007-09-24 patchlevel 111)
[universal-darwin9.0].
Can someone kindly give me the exact steps (from installing the
modules to using Ruby DBI) to run the simplest possible select query
form MySql DB? Again, sorry for the newbie question.
Csongor wrote:
| I’m sorry to ask such a newbie question but I wasn’t able to figure
| this out yet. I just want to write a simple Ruby program that can
| select data from a MySql database. I assume that Ruby DBI would be the
| easiest way to go but I don’t think I have the required modules/gems
| installed. I can’t even do a require ‘dbi’, it throws the following
| error: LoadError: no such file to load – dbi
are you using require ‘rubygems’ on the top of your script (before you
load DBI)?
If not, try that.
(‘export RUUBYOPTS=rubygems’ should fix that permanently, I think)
~ - You know you’ve been hacking too long when…
…your radio is playing, and you’re starting a big compile on your home
box, and it occurs to you that the music will begin to get a bit jerky,
because you think it’s playing through the computer and you’re not quite
sure how well it’ll multitask with the compile.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
Hey,
Well there may be a couple of reons involved why you are getting the
error.
Please check with your installtion of ruby gems.
Once your done check wether ‘gem’ command is working or not in your
terminal.
If something goes wrong with the installtion then you can make it with
up
the dependencies.
once you are done with the process…In your irb please check with the
‘require dbi’ .If it returns true then you are ready to go ahead with
the
mysql.
Csongor wrote:
| Philip,
|
| Thanks for the response. I wasn’t, but I just did a quick test and
| require ‘rubygems’ is giving me a false. Look:
|
| sh-3.2# ruby -v
| ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0]
| sh-3.2# gem -v
| 1.1.1
| sh-3.2# irb
|>> require ‘rubygems’
| => false
|
| Any ideas?
Well, it looks like you didn’t install Ruby-DBI, since ‘dbi’ is what you
need for the require.
Fortunately, the RDoc files for Ruby-DBI show you the installation:
~ - You know you’ve been hacking too long when…
…you start dreaming code.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
Try this. I am working windows here.I think it will work in Mac also…
TRY.rb
=begin
OS : Windows here (May be same MAC OSx)
Ruby : 1.8.6
DB :Mysql
Gem :> gem install mysql
=end
require “mysql” #require mysql gem
connection = Mysql.connect(“localhost”, “root”, “”, “cdcol”) #localhost = hostname #root = username of mysql DB
#“”=password of mysql DB #cdcol = DB name
output = connection.query(“SELECT * FROM cds;”) #cds = table name
output.each do |x|
puts x.inspect
end
~ There’s never enough time to do all the nothing you want.
– Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org