|
Re: Using DBI and MySQL gems: msg#02290ruby-talk
Erik Hollensbe wrote: > David Bennett wrote: >> Owein Herrmann wrote: >>> require 'dbi' >> >> Try upper case: >> require 'DBI' >> >> It works for me. Dunno why. > > Try adding a: > > gem 'dbd-mysql' > > after the require 'dbi'. > > Basically, you have to have both packages loaded so DBI can require > them. > > If you've done a setup.rb installation, you shouldn't have any issues > here. Hey all... I'm having a lot of problem trying to use DBI with Mysql in last 2 days and I have no idea of how to do it, and I've already tried dozens of different solutions. Here is a brief history of my tests: The code I'm testing is: require "dbi" (or "DBI") class test_dbi def selectAll begin # connect to the MySQL server dbh = DBI.connect("DBI:Mysql:CMASDB_V41_2:192.168.253.29", "cmasAdmin", "cmas_admin") # 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 end end With this code I got the follwing error message: Could not load driver (uninitialized constant Mysql::Driver) RAILS_ROOT: C:/eclipse322/workspace/cmas41_rails Application Trace | Framework Trace | Full Trace C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:511:in `load_driver' C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in `_get_full_driver' C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in `connect' app/models/test_dbi.rb:11:in `selectAll' Then I tried: require "rubygems" require "dbi" gem "dbd-mysql" And I got: Could not load driver (no such file to load -- DBD/mysql/mysql) RAILS_ROOT: C:/eclipse322/workspace/cmas41_rails Application Trace | Framework Trace | Full Trace C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:511:in `load_driver' C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in `_get_full_driver' C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in `connect' app/models/test_dbi.rb:13:in `selectAll' So I figured out that there is no mysql directory in C:\ruby\lib\ruby\site_ruby\1.8\DBD And I copied the file C:\ruby\lib\ruby\gems\1.8\gems\dbd-mysql-0.4.3\lib\dbd\Mysql.rb to the folder C:\ruby\lib\ruby\site_ruby\1.8\DBD\MYSQL. And tried again and have a different error: Could not load driver (uninitialized constant DBI::TypeUtil) RAILS_ROOT: C:/eclipse322/workspace/cmas41_rails Application Trace | Framework Trace | Full Trace C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:511:in `load_driver' C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:401:in `_get_full_driver' C:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:381:in `connect' app/models/fedag_dbi.rb:13:in `selectAll' I installed using gem install the follwing packages: C:\>gem install dbi Successfully installed dbi-0.4.2 1 gem installed Installing ri documentation for dbi-0.4.2... Installing RDoc documentation for dbi-0.4.2... C:\>gem instal dbd-mysql Successfully installed dbd-mysql-0.4.3 1 gem installed Installing ri documentation for dbd-mysql-0.4.3... Installing RDoc documentation for dbd-mysql-0.4.3... C:\>gem install dbd-pg Successfully installed dbd-pg-0.3.8 1 gem installed Installing ri documentation for dbd-pg-0.3.8... Installing RDoc documentation for dbd-pg-0.3.8... C:\> C:\> C:\> C:\>gem install ruby-oci8 Successfully installed ruby-oci8-2.0.2-x86-mswin32-60 1 gem installed Installing ri documentation for ruby-oci8-2.0.2-x86-mswin32-60... Installing RDoc documentation for ruby-oci8-2.0.2-x86-mswin32-60... My gem list is: C:\>gem list *** LOCAL GEMS *** actionmailer (2.1.2) actionpack (2.1.2) activerecord (2.1.2) activeresource (2.1.2) activesupport (2.1.2) builder (2.1.2) cgi_multipart_eof_fix (2.5.0) ci_reporter (1.6.0) columnize (0.3.0) commonwatir (1.6.2) dbd-mysql (0.4.3) dbd-pg (0.3.8) dbi (0.4.2) deprecated (2.0.1) firewatir (1.6.2) fxri (0.3.6) fxruby (1.6.6) gem_plugin (0.2.3) highline (1.5.1) hoe (1.12.2) hpricot (0.4) linecache (0.43) log4r (1.0.5) mongrel (1.1.5) mongrel_cluster (1.0.5) mysql (2.7.3) net-sftp (2.0.2) net-ssh (2.0.11) paginator (1.1.1) pg (0.8.0) rails (2.1.2) rake (0.8.7, 0.7.2) rcov (0.8.1.2.0) ruby-debug (0.10.3) ruby-debug-base (0.10.3) ruby-oci8 (2.0.2) ruby-postgres (0.7.1.2006.04.06) rubyforge (1.0.3) rubygems-update (1.3.3) s4t-utils (1.0.4) sources (0.0.1) tzinfo (0.3.13) user-choices (1.1.6) watir (1.6.2) win32-api (1.4.0) win32-clipboard (0.4.1) win32-dir (0.3.1) win32-eventlog (0.4.3) win32-file (0.5.3) win32-file-stat (1.2.3) win32-process (0.6.0, 0.5.1) win32-sapi (0.1.3) win32-sound (0.4.0) windows-api (0.3.0) windows-pr (1.0.5, 0.6.2) xml-simple (1.0.12) I'm working on this for the last 2 days and I have no idea of how to solve this. Any help will be apreciated! --Helio -- Posted via http://www.ruby-forum.com/.
|
|
||||||||||||||||||||||||||
|
|
|
| News | Mail Home | sitemap | FAQ | advertise |