Problem in accessing MySQL


#1

Hi,
I’m new to ruby and facing the following problem in connecting to MySQL
from my script.

Here is the script:
#!/usr/bin/ruby -w
#~ # simple.rb - simple MySQL script using Ruby DBI module
gem “mysql”
gem “dbi”
require “dbi”
#~ gem ‘dbd-mysql’
begin
# connect to the MySQL server
dbh=DBI.connect(“DBI:Mysql::”, “user”,
“password”)

 # get server version string and display it
 row = dbh.select_one("SELECT VERSION()")
 puts "Server version: " + row[0]

rescue DBI::DatabaseError => e
puts “An error occurred”
puts “Error code: #{e.err}”
puts “Error message: #{e.errstr}”
ensure
# disconnect from server
dbh.disconnect if dbh
end

Here is the error:

ruby simple.rb
c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:294:in
load_driver': Unable to load driver 'Mysql' (underlying error: uninitialized constant DBI::DBD::Mysql) (DBI::InterfaceError) from c:/ruby/lib/ruby/1.8/monitor.rb:242:insynchronize’
from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:236:in
load_driver' from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:154:in_get_full_driver’
from c:/ruby/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi.rb:139:in
`connect’
from simple.rb:10
Exit code: 1