# 2 different databases in 1 application? MySQL & Informix

**URL:** <https://www.ruby-forum.com/t/2-different-databases-in-1-application-mysql-informix/119317>\
**Category:** Rails\
**Created:** [November 5, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/2-different-databases-in-1-application-mysql-informix/119317 "2007-11-05T23:59:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![malooking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@malooking](https://www.ruby-forum.com/u/malooking)\
**Post date:** [November 5, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/2-different-databases-in-1-application-mysql-informix/119317/1 "2007-11-05T23:59:00Z")

</div>

Please, i need help.

i wonder if rail allows to have 1 legacy database in informix and other  
mysql database (no legacy) in the same application.

I need to query in the informix database and manipulate data to save in  
mysql.

It is posible?? if it is, how? any guide? tutorial? link?

I’ll appreciate any help.

best regards.

Mary,  
Baja California

Soon Baja 1000!

---

<div class="post-metadata">

**Author:** ![malooking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@malooking](https://www.ruby-forum.com/u/malooking)\
**Post date:** [November 6, 2007, 12:03am UTC](https://www.ruby-forum.com/t/2-different-databases-in-1-application-mysql-informix/119317/2 "2007-11-06T00:03:01Z")

</div>

sure…look at the docs for ActiveRecord::Base.establish\_connection

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001086)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

If you google on something like “multiple databases in rails” you will  
find many examples. You can also store your db information in  
database.yml and refer to it by name with establish\_connection

-Bill

Mary Nu wrote:

> I’ll appreciate any help.
> 
> best regards.
> 
> Mary,  
> Baja California
> 
> Soon Baja 1000!

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![malooking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@malooking](https://www.ruby-forum.com/u/malooking)\
**Post date:** [November 6, 2007, 4:32pm UTC](https://www.ruby-forum.com/t/2-different-databases-in-1-application-mysql-informix/119317/3 "2007-11-06T16:32:05Z")

</div>

Hi Mary,

I’ve got one similar project where I perform some queries on a legacy  
MS SQL database and use a (new) My SQL database to manage the newer  
part of the system. It is possible and it works OK. I had to go  
through a few nightmares with MS SQL / RoR (bugs in the adapter,  
problems with specific field types, problems with pagination, etc),  
but I got it to do what I need.

The way I’m doing it is pretty simple, no plug-in, all based on pure  
rails. This is how:

1. in you models pointing to the legacy database, you might need to  
specify table names and primary key columns as they probably wont  
follow RoR default naming conventions:

class Consultants \< External  
set\_table\_name “Consultants”  
id = “ConsIntID”

```
 .....

```

end

You can also see that I’m deriving Consultants from “External”. This  
is how the External model looks like:

class External \< ActiveRecord::Base  
self.abstract\_class = true  
establish\_connection :yourlegacydb  
end

Then you can have any model pointing to the legacy DB derived from  
External, and you can configure your connection to your legacy db in  
your database.yml file just like this:

yourlegacydb:  
adapter : …  
…

Good luck,  
Seb

---

<div class="post-metadata">

**Author:** ![malooking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@malooking](https://www.ruby-forum.com/u/malooking)\
**Post date:** [November 6, 2007, 12:07am UTC](https://www.ruby-forum.com/t/2-different-databases-in-1-application-mysql-informix/119317/4 "2007-11-06T00:07:42Z")

</div>

Quick google search turned up this:

[http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases](http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases)

Mary Nu wrote:

> I’ll appreciate any help.
> 
> best regards.
> 
> Mary,  
> Baja California
> 
> Soon Baja 1000!

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![malooking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/77aa72/32.png) [@malooking](https://www.ruby-forum.com/u/malooking)\
**Post date:** [November 13, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/2-different-databases-in-1-application-mysql-informix/119317/5 "2007-11-13T17:11:03Z")

</div>

Thanks a lot sbrocher. I already make a test and it works.
