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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mohamed Muneer Selim
    New Member
    • Sep 2007
    • 3

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

    can ruby access, existing MySQL databases to modify
    (add information, search or running queries)

    if yes please let me know
  • rustyc
    New Member
    • Sep 2007
    • 5

    #2
    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 "Programmin g 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....

    Comment

    • improvcornartist
      Recognized Expert Contributor
      • May 2007
      • 303

      #3
      You may need to create a new data source. Then you should be able to connect with
      [CODE=ruby]
      DBI.connect("db i:ODBC:MyDSNNam e", "username", "password")
      [/CODE]

      Comment

      • rustyc
        New Member
        • Sep 2007
        • 5

        #4
        Boy, improvcornartis t, 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....

        Comment

        • Mohamed Muneer Selim
          New Member
          • Sep 2007
          • 3

          #5
          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

          Comment

          Working...