Connection to Mysql

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 :wink:

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

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

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.