How to connect to Mysql & Query for Database Tables

Hi Guys,
Ruby imposes several way of connecting to Mysql (DBI,activerecord…)
Database using ruby code. Let me know if anybody knows how to connect to
mysql the easiest way.
I am getting all sorts of error trying to connect to mysql. I am using
Windows XP OS.
Hope to hear from you guys soon!!

Cheers

Hi Guys,
Ruby imposes several way of connecting to Mysql (DBI,activerecord…)
Database using ruby code. Let me know if anybody knows how to connect to
mysql the easiest way.

DBI is generally an easy way.
http://www.kitebird.com/articles/ruby-dbi.html

You have to
gem install mysql
gem install dbd-mysql
gem install dbi
before using it.

HTH.

Jeff P. wrote:

Hi Guys,
Ruby imposes several way of connecting to Mysql (DBI,activerecord…)
Database using ruby code. Let me know if anybody knows how to connect to
mysql the easiest way.

DBI is generally an easy way.
http://www.kitebird.com/articles/ruby-dbi.html

You have to
gem install mysql
gem install dbd-mysql
gem install dbi
before using it.

HTH.

Hi,

On Trying, " gem install mysql " , i get the following error:

C:\Documents and Settings\user1\Desktop>gem install mysql
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

D:/Softwares/ruby/bin/ruby.exe extconf.rb
checking for main() in libmysql.lib… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for mo
details.

Thanks

Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for mo
details.

Well, you have to install mysql client before all the operation.
There have to be:

/usr/lib/libmysqlclient.a
/usr/lib/libmysqlclient.so

in my Linux OS.

Jeff.

Idealone I. wrote:

Hi Guys,
Ruby imposes several way[s] of […] using ruby code.

That’s certainly an interesting observation.

Albert S. wrote:

Idealone I. wrote:

Hi Guys,
Ruby imposes several way[s] of […] using ruby code.

That’s certainly an interesting observation.

Guys,
I eventually got it working, just adding gem ‘dbi’…

require “rubygems”
gem “dbi”
require “dbi”

def connect_to_mysql()
puts “\nConnecting to MySQL…”
me = DBI.connect(“dbi:Mysql:DBname:localhost”, “root”, “”)
query = me.prepare(“SELECT * FROM browsers where id > ?”)
query.execute(0)
while row = query.fetch() do
puts row
end

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs