Ruby connection to MySql

I'm going thru the "PickAxe" book but can find only limited information
in it regarding how Ruby connects to and uses MySql..

Is there any documentation available in regard to this?

Thanks,
Pat

···

--
Posted via http://www.ruby-forum.com/.

Here is the website of the (well, 'a'..) Ruby library for MySQL:
http://www.tmtm.org/en/mysql/ruby/

This is a relatively low-level way to work with a database.
ActiveRecord, Og, rBATIS, etc, are higher-level ORM libraries that
make life easier.

···

On 9/21/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

I'm going thru the "PickAxe" book but can find only limited information
in it regarding how Ruby connects to and uses MySql..

Is there any documentation available in regard to this?

As far as I know, Ruby itself has no language support for
MySQL in particular or databases in general. However, a
number of libraries have been developed to allow Ruby to
interact with these facilities.

The most popular interface, Active Record, is part of the
"Ruby on Rails" effort. Several books are available on
this topic, including:

  Agile Web Development with Rails
  Rails Recipes
  Ruby for Rails
  Ruby on Rails: Up and Running

General coverage of database usage in Ruby is given in:

  Enterprise Integration with Ruby

This book also covers LDAP, XML, and distributed apps. I
like the book's approach, which starts with low-level
solutions and works its way up to more abstract interfaces.

This allows the reader to appreciate the problems that the
higher-level solutions are dealing with (and, if it becomes
necessary to revert to a lower-level approach, what options
are available).

-r

···

At 3:13 AM +0900 9/22/06, Patrick Lynch wrote:

I'm going thru the "PickAxe" book but can find only
limited information in it regarding how Ruby connects
to and uses MySql..

Is there any documentation available in regard to this?

--
http://www.cfcl.com/rdm Rich Morin
http://www.cfcl.com/rdm/resume rdm@cfcl.com
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development

Hi Pat,

Here's what I've been able to gather on the matter:
http://www.simisen.com/jmg/notes/ruby/db.html

---John

···

On 9/21/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

I'm going thru the "PickAxe" book but can find only limited information
in it regarding how Ruby connects to and uses MySql..

Is there any documentation available in regard to this?

John Gabriele wrote:

···

On 9/21/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

I'm going thru the "PickAxe" book but can find only limited information
in it regarding how Ruby connects to and uses MySql..

Is there any documentation available in regard to this?

Hi Pat,

Here's what I've been able to gather on the matter:
http://www.simisen.com/jmg/notes/ruby/db.html

---John

Hi John,
Thanks for the link...I'll work it and let you know how I make out...
I hope I can return the favor someday.
Ciao,
Pat

--
Posted via http://www.ruby-forum.com/\.

Patrick Lynch wrote:

John Gabriele wrote:

I'm going thru the "PickAxe" book but can find only limited information
in it regarding how Ruby connects to and uses MySql..

Is there any documentation available in regard to this?

Hi Pat,

Here's what I've been able to gather on the matter:
http://www.simisen.com/jmg/notes/ruby/db.html

---John

Hi John,
Thanks for the link...I'll work it and let you know how I make out...
I hope I can return the favor someday.
Ciao,
Pat

Good morning,
I should have noted that I'm trying to get Ruby to talk to MySql on a
Windows XP/Pro box.

I was able to get Rails working with MySql and I can't understand why
there is no support for MySql and other DBMSs in Ruby. The 'Pick Axe'
makes a reference to 'dbi' on page 157, but offers no help in installing
it...bummer.

So, for my Ruby app, I'll simply use a flat file and abandon my effort
to interface with MySql. What a shame.

In addition, classes mentioned in "Mastering Perl/Tk' (such as
CamvasPlot) cannot, AFAIK, be used with Ruby...if anyone knows how to
make these Perl classes known to Ruby, please let me know...

My next app will be put up with Rails...wish me luck...

···

On 9/21/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

--
Posted via http://www.ruby-forum.com/\.

Patrick Lynch wrote:

Patrick Lynch wrote:

John Gabriele wrote:

I'm going thru the "PickAxe" book but can find only limited information
in it regarding how Ruby connects to and uses MySql..

Is there any documentation available in regard to this?

Hi Pat,

Here's what I've been able to gather on the matter:
http://www.simisen.com/jmg/notes/ruby/db.html

---John

Hi John,
Thanks for the link...I'll work it and let you know how I make out...
I hope I can return the favor someday.
Ciao,
Pat

Good morning,
I should have noted that I'm trying to get Ruby to talk to MySql on a Windows XP/Pro box.

I was able to get Rails working with MySql and I can't understand why there is no support for MySql and other DBMSs in Ruby. The 'Pick Axe' makes a reference to 'dbi' on page 157, but offers no help in installing it...bummer.

So, for my Ruby app, I'll simply use a flat file and abandon my effort to interface with MySql. What a shame.

Um... If you've got Rails working with MySQL, you've got Ruby working with MySQL. You should just be able to require 'mysql' from an arbitrary script and have it work, when Rails is installed.

···

On 9/21/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

--
Alex

Ruby has tons of database support. I routinely use MySQL, Oracle,
PostgreSQL, and SQLite from Ruby code on my Windows XP box.
You're just giving up too quickly.

···

On 9/28/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

Patrick Lynch wrote:
> John Gabriele wrote:
>> On 9/21/06, Patrick Lynch <lynchnco@patmedia.net> wrote:
>>> I'm going thru the "PickAxe" book but can find only limited information
>>> in it regarding how Ruby connects to and uses MySql..
>>>
>>> Is there any documentation available in regard to this?
>>>
>>
>> Hi Pat,
>>
>> Here's what I've been able to gather on the matter:
>> http://www.simisen.com/jmg/notes/ruby/db.html
>>
>> ---John
>
> Hi John,
> Thanks for the link...I'll work it and let you know how I make out...
> I hope I can return the favor someday.
> Ciao,
> Pat

Good morning,
I should have noted that I'm trying to get Ruby to talk to MySql on a
Windows XP/Pro box.

I was able to get Rails working with MySql and I can't understand why
there is no support for MySql and other DBMSs in Ruby. The 'Pick Axe'
makes a reference to 'dbi' on page 157, but offers no help in installing
it...bummer.

So, for my Ruby app, I'll simply use a flat file and abandon my effort
to interface with MySql. What a shame.

In addition, classes mentioned in "Mastering Perl/Tk' (such as
CamvasPlot) cannot, AFAIK, be used with Ruby...if anyone knows how to
make these Perl classes known to Ruby, please let me know...

My next app will be put up with Rails...wish me luck...

Wilson Bilkovich wrote:

···

On 9/28/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

>>

to interface with MySql. What a shame.

In addition, classes mentioned in "Mastering Perl/Tk' (such as
CamvasPlot) cannot, AFAIK, be used with Ruby...if anyone knows how to
make these Perl classes known to Ruby, please let me know...

My next app will be put up with Rails...wish me luck...

Ruby has tons of database support. I routinely use MySQL, Oracle,
PostgreSQL, and SQLite from Ruby code on my Windows XP box.
You're just giving up too quickly.

Wilson,
Thanks for the 'heads up'...can you please give me some direction to get
Ruby talking to MySql?
Pat

--
Posted via http://www.ruby-forum.com/\.

First, either:
gem install mysql --remote
(pick the Win32 version when/if given a choice.)

..or install it by hand from here (needs a compiler):
http://www.tmtm.org/en/mysql/ruby/

Once you have that, try running this code.

require 'rubygems'
require 'mysql'

HOST = 'localhost'
USER = 'root'
PASSWORD = nil
DATABASE = 'put_your_database_name_here'
connection = Mysql.real_connect(HOST, USER, PASSWORD, DATABASE)
connection.query "show tables" do |result_set|
  result_set.each {|row| puts row}
end

This is painfully low-level, and not really how anyone should be
writing database code in Ruby. However, if it prints out a list of the
tables in your database, you know it's working.

In real life, you should use something like DBI, ActiveRecord, or Og.
That way you aren't dealing with the nitty-gritty connection details
all the time, and it is easier to switch databases later.

DBI is also fairly low-level, but at least it is the same across all
database platforms.

···

On 9/28/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

Wilson Bilkovich wrote:
> On 9/28/06, Patrick Lynch <lynchnco@patmedia.net> wrote:
>> >>
>>
>> to interface with MySql. What a shame.
>>
>> In addition, classes mentioned in "Mastering Perl/Tk' (such as
>> CamvasPlot) cannot, AFAIK, be used with Ruby...if anyone knows how to
>> make these Perl classes known to Ruby, please let me know...
>>
>> My next app will be put up with Rails...wish me luck...
>>
>
> Ruby has tons of database support. I routinely use MySQL, Oracle,
> PostgreSQL, and SQLite from Ruby code on my Windows XP box.
> You're just giving up too quickly.

Wilson,
Thanks for the 'heads up'...can you please give me some direction to get
Ruby talking to MySql?
Pat

Wilson Bilkovich wrote:

>> My next app will be put up with Rails...wish me luck...

First, either:
gem install mysql --remote
(pick the Win32 version when/if given a choice.)

..or install it by hand from here (needs a compiler):
MySQL/Ruby

Once you have that, try running this code.

require 'rubygems'
require 'mysql'

HOST = 'localhost'
USER = 'root'
PASSWORD = nil
DATABASE = 'put_your_database_name_here'
connection = Mysql.real_connect(HOST, USER, PASSWORD, DATABASE)
connection.query "show tables" do |result_set|
  result_set.each {|row| puts row}
end

This is painfully low-level, and not really how anyone should be
writing database code in Ruby. However, if it prints out a list of the
tables in your database, you know it's working.

In real life, you should use something like DBI, ActiveRecord, or Og.
That way you aren't dealing with the nitty-gritty connection details
all the time, and it is easier to switch databases later.

DBI is also fairly low-level, but at least it is the same across all
database platforms.

Worked beautifully! THX. I had been working with MySql previously so I
had to check on the 'put_your_database_name_here' and thankfully I save
the password.
(I'm not quite sure what would have to be done if I had lost the
password).

I've worked extensively with DB2 and SQL Server 2000, so working at a
low level is no big woops for me, actually, I enjoy working at the this
level...

If you attend any of the Ruby User Group Meetings, let me know, I'd like
to thank you in person...

THX,
Pat

···

On 9/28/06, Patrick Lynch <lynchnco@patmedia.net> wrote:

--
Posted via http://www.ruby-forum.com/\.