On 10/4/2010 1:30 PM, Ed Reed wrote:
> Okay I've decided to start from scratch,... again. It's the start of a 
> new week and I've got a positive attitude so here we go. I read this, 
> http://www.kitebird.com/articles/ruby-dbi.html, and wanted to try the 
> first test script. When I do, I get the following error.
> 
> C:\PROGRA~2\APACHE~1\Apache2.2\htdocs\dbi-scripts>simple.rb
> lib/rational.rb is deprecated
> C:/Ruby/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles.rb:12: 
> warning: optional boolean argument is obsoleted
> C:/Ruby/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:300:in `block in 
> load_driver': Unable to load driver 'Mysql' (underlying error: 
> uninitialized constant DBI::DBD::Mysql) (DBI::InterfaceError)
>         from C:/Ruby/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
>         from 
> C:/Ruby/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:242:in 
> `load_driver'
>         from 
> C:/Ruby/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:160:in 
> `_get_full_driver'
>         from 
> C:/Ruby/lib/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
>         from 
> C:/PROGRA~2/APACHE~1/Apache2.2/htdocs/dbi-scripts/simple.rb:9:in 
> `<main>'
> 
> 
> Here are the steps I took to get to here.
> Fresh install of Ruby 1.9.2 using 
> http://rubyforge.org/frs/download.php/72170/rubyinstaller-1.9.2-p0.exe 
> followed by,
> gem install dbd
> gem install dbi-mysql
> gem install dbi-odbc

The above gem commands have typos.  They should be:

gem install dbi
gem install dbd-mysql
gem install dbd-odbc

> gem install mysql

This is fetched automatically when installing the dbd-mysql gem.  FYI.

> Then from the command prompt I tried to run the simple.rb script from 
> http://www.kitebird.com/articles/ruby-dbi.html. The contents of which 
> are,
> 
> #!/ruby -w
> # simple.rb - simple MySQL script using Ruby DBI module
> 
> require "dbi"
> 
> begin
>   # connect to the MySQL server
> #@ _CONNECT_
>   dbh = DBI.connect("DBI:Mysql:test:localhost", "root", "password")
> #@ _CONNECT_
>   # get server version string and display it
>   row = dbh.select_one("SELECT VERSION()")
>   puts "Server version: " + row[0]
> #@ _EXCEPTION_
> rescue DBI::DatabaseError => e
>   puts "An error occurred"
>   puts "Error code: #{e.err}"
>   puts "Error message: #{e.errstr}"
> #@ _EXCEPTION_
> ensure
>   # disconnect from server
>   dbh.disconnect if dbh
> end
> 
> I'm open to suggestions?

It's necessary to download the MySQL client DLL and copy it into Ruby's
bin directory if you want to use the mysql gem on Windows.  I downloaded
mysql-connector-c-noinstall-6.0.2-win32.zip from
http://dev.mysql.com/downloads/connector/c/ and copied the
lib/libmysql.dll file from the archive directly into Ruby's bin
directory to resolve this issue.

FYI, things are much easier under Linux. :-)  I wonder if it's possible
for the mysql gem for Windows builds to provide this DLL.

-Jeremy