How to connect to Mysql & Query for Database Tables

Discussion in 'Ruby' started by Idealone Ideally, Jan 27, 2010.

  1. 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
    --
    Posted via http://www.ruby-forum.com/.
    Idealone Ideally, Jan 27, 2010
    #1
    1. Advertising

  2. Idealone Ideally

    Jeff Peng Guest


    > 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 Peng, Jan 27, 2010
    #2
    1. Advertising

  3. Jeff Peng 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
    --
    Posted via http://www.ruby-forum.com/.
    Idealone Ideally, Jan 27, 2010
    #3
  4. Idealone Ideally

    Jeff Peng Guest


    > 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.
    Jeff Peng, Jan 27, 2010
    #4
  5. Idealone Ideally wrote:
    > Hi Guys,
    > Ruby imposes several way of [...] using ruby code.


    That's certainly an interesting observation.
    --
    Posted via http://www.ruby-forum.com/.
    Albert Schlef, Jan 27, 2010
    #5
  6. Albert Schlef wrote:
    > Idealone Ideally wrote:
    >> 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
    --
    Posted via http://www.ruby-forum.com/.
    Idealone Ideally, Jan 28, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcus Krieger

    jdbc connect to mysql database

    Marcus Krieger, Dec 10, 2004, in forum: Java
    Replies:
    2
    Views:
    13,175
    Ian T
    Dec 11, 2004
  2. Chris Brat
    Replies:
    5
    Views:
    684
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=
    Aug 22, 2006
  3. Pen Ttt

    connect mysql:show tables

    Pen Ttt, Apr 26, 2010, in forum: Ruby
    Replies:
    2
    Views:
    122
    ghorner
    Apr 26, 2010
  4. Allen Marshall
    Replies:
    1
    Views:
    178
    Gunnar Hjalmarsson
    Jan 24, 2004
  5. Replies:
    2
    Views:
    260
Loading...

Share This Page