Connecting Tech Pros Worldwide Help | Site Map

how to connect to a database by ruby, and modify, add or delete

Newbie
 
Join Date: Sep 2007
Location: Egypt
Posts: 3
#1: Sep 6 '07
can ruby access, existing MySQL databases to modify
(add information, search or running queries)

if yes please let me know
Newbie
 
Join Date: Sep 2007
Posts: 5
#2: Sep 6 '07

re: how to connect to a database by ruby, and modify, add or delete


Yes, you should be able to do that, but it will be MUCH easier to do if your database follows the rules for table names.

I'd suggest a look at some of the standard tutorials, or even (gasp) go get the 'official' ruby on rails book - go to http://www.rubyonrails.org/ and find the 'agile web development with rails' book. Shoot, you can even download it (for a price).

Since you ask only about ruby, and not rails, the 'other' main book on Ruby alone might be all you need. Again, google is your friend here - look for "Programming Ruby: the Pragmatic Programmer's Guide".

Note that, in my experience, the Rails book is enough to get you going, but not necessarily in the best direction. I'm still fighting with my web application, and I finally find out that I'm woefully messed up in handling the transition from 'thing on the web page that came from the database' to 'saving the changed thing back to the database' when the web page is of my creation and not of the scaffold....
Expert
 
Join Date: May 2007
Posts: 213
#3: Sep 7 '07

re: how to connect to a database by ruby, and modify, add or delete


You may need to create a new data source. Then you should be able to connect with
Expand|Select|Wrap|Line Numbers
  1. DBI.connect("dbi:ODBC:MyDSNName", "username", "password")
  2.  
Newbie
 
Join Date: Sep 2007
Posts: 5
#4: Sep 7 '07

re: how to connect to a database by ruby, and modify, add or delete


Boy, improvcornartist, you got me - I forgot all about the db setup config file in rails. I should have mentioned 'config/database.yml' as where you'd need to go set up your database, IF you are using Ruby on Rails....
Newbie
 
Join Date: Sep 2007
Location: Egypt
Posts: 3
#5: Sep 8 '07

re: how to connect to a database by ruby, and modify, add or delete


pardon, but it seems I'm having problems in installing ruby

first I installed ruby
then I installed gems then rails but the problem is that I want an interface for ruby instead of using bash, it might be confusing sometimes
also I want to know how to run ruby (I've been using irb)
and now I'm trying to install NetBeans

that if you offered help, I would be thankful
thanks in advance
Reply