Hello everyone I''m developing an aplication in rails, and need to connect to a diferente database to set up a migration tool, from an old aplication in php to the new application in rails ;) So, I need a "low level" con to the old app so I can transfer the data. And I need to do it in rails to reuse the app already done in rails. Can someone help ? Thanks JP -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
When I need to do this, I create a script that loads up the rails
environment so I have access to all the application stuff, and then
use a manual database connection. Let''s say we''re importing
customers
from an old database:
------- /scripts/import_from_old_db.rb
#!/usr/bin/env ruby
require File.dirname(__FILE__) + ''/../config/environment''
require ''mysql''
dbh = Mysql.real_connect("mydatabase", "user",
"pass",
"myolddatabase")
old_customers = dbh.query("select * from tblCustomers")
customers = []
while old_customer = old_customers.fetch_hash do
customers << {:name => customer["Name"], :address =>
customer["Add"]}
end
Customer.create(customers)
dbh.close
---------
There is more information about ruby-mysql here:
http://www.kitebird.com/articles/ruby-mysql.html. You could also use
the rails connection adapters to query the old database - I just
haven''t done that yet :0)
Hope that helps,
Steve
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks Steve! I,m going to do a little bit different since I''m going to do a connection from within the application. I''m going to use mylsq/ruby too. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---