How to connect to Mysql & Query for Database Tables

I

Idealone Ideally

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
 
I

Idealone Ideally

Jeff said:
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
 
J

Jeff Peng

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.

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.
 
I

Idealone Ideally

Albert said:
Idealone said:
Hi Guys,
Ruby imposes several way 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
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top