Newbie question about MySQL on Windows XP Pro

I have a brand new installation of latest Ruby:
C:\rubysrcs\ruby_tut>ruby -v
    ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

and I installed mysql:
C:\perlsrcs\ebay>gem install mysql
Select which gem to install for your platform (i386-mswin32)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation

1

Successfully installed mysql-2.7.3-mswin32
Installing ri documentation for mysql-2.7.3-mswin32...
Installing RDoc documentation for mysql-2.7.3-mswin32...
While generating documentation for mysql-2.7.3-mswin32
... MESSAGE: Unhandled special: Special: type=17, text="<!-- $Id:
README.html,v 1.20 2006-12-20 05:31:5
2 tommy Exp $ -->"
... RDOC args: --op C:/ruby/lib/ruby/gems/1.8/doc/mysql-2.7.3-mswin32/
rdoc --exclude ext --main README --
quiet ext README docs/README.html
(continuing with the rest of the installation)

I then tried running this ruby script:

  require 'dbi'

  db_name = "cookbook"
  host_name = "localhost"
  user_name = "cb_user"
  password = "cb_pass"
  dsn = "DBI:mysql:host=#{host_name};database=#{db_name}"

  # Connect to a database, old style
  dbh = DBI.connect(dsn, user_name, password)

  # And finally, disconnect
  dbh.disconnect

unfortunately all I get is:
  C:\rubysrcs\ruby_tut>ruby -w test_handle.rb
  C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:499:in `load_driver': is
not a class/module (TypeError)
        from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in
`_get_full_driver'
        from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in
`connect'
        from test_handle.rb:11

I really did try a host of other things too, but this seemed like the
best way to present problem!

I think you need to include 'rubygems' as well like this:

require 'rubygems'
require 'dbi'

Hope that helps :slight_smile:

Grehom wrote:

···

I then tried running this ruby script:

  require 'dbi'

  db_name = "cookbook"
  host_name = "localhost"
  user_name = "cb_user"
  password = "cb_pass"
  dsn = "DBI:mysql:host=#{host_name};database=#{db_name}"

  # Connect to a database, old style
  dbh = DBI.connect(dsn, user_name, password)

  # And finally, disconnect
  dbh.disconnect

No, thanks but it didn't work:

C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:499:in `load_driver': is
not a class/module (TypeError)
        from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in
`_get_full_driver'
        from C:/Ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in
`connect'
        from test_handle.rb:12