# Mysql

**URL:** <https://www.ruby-forum.com/t/mysql/88010>\
**Category:** Rails\
**Created:** [March 7, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/mysql/88010 "2007-03-07T15:18:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![refaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@refaris](https://www.ruby-forum.com/u/refaris)\
**Post date:** [March 7, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/mysql/88010/1 "2007-03-07T15:18:13Z")

</div>

I am looking for a way to access a database without active record.  
Basically when i call a certain action, I want to delete a customer from  
the database linked via active record, and insert that customer into  
another database on the same server but not linked to this RoRapp.

Suggestions?

---

<div class="post-metadata">

**Author:** ![refaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@refaris](https://www.ruby-forum.com/u/refaris)\
**Post date:** [March 7, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/mysql/88010/2 "2007-03-07T15:47:44Z")

</div>

> I am looking for a way to access a database without active record.  
> Basically when i call a certain action, I want to delete a customer from  
> the database linked via active record, and insert that customer into  
> another database on the same server but not linked to this RoRapp.

you can still use AR even through multiple connections. Each AR model  
can have a different database connection. By default they will use the  
connection associated to the current environment, but you can just do

class MyModel\< ActiveRecord::Base  
| establish\_connection :differentdb  
end  
|  
And your “MyModel” objects will use the :differentdb connection, which  
will be the entry in your database.yml file under the name differentdb:

If you are going to use many models with a sepparate connection you can  
even make an “abstract” AR class with only that line for establishing  
the connection and then have your models extend from this one.

Of course you can still use Ruby DBI and make all the process manually,  
but in that case you have to take care of managing the connection and  
with AR you can just forget about low level and concentrate on business  
logic.

regards,

javier ramirez

## –

Estamos de estreno… si necesitas llevar el control de tus gastos  
visita [http://www.gastosgem.com](http://www.gastosgem.com) !!Es gratis!!
