Problem in accessing MySQL

B

Bhaskar Ms

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:<db-name>:<remote-Host>", "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:in `synchronize'
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top