# Can I access another apps mysql database with my rails app?

**URL:** <https://www.ruby-forum.com/t/can-i-access-another-apps-mysql-database-with-my-rails-app/187268>\
**Category:** Rails\
**Created:** [April 20, 2010, 9:19pm UTC](https://www.ruby-forum.com/t/can-i-access-another-apps-mysql-database-with-my-rails-app/187268 "2010-04-20T21:19:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@ast](https://www.ruby-forum.com/u/ast)\
**Post date:** [April 20, 2010, 9:19pm UTC](https://www.ruby-forum.com/t/can-i-access-another-apps-mysql-database-with-my-rails-app/187268/1 "2010-04-20T21:19:47Z")

</div>

Sorry if the answer is obvious (nube alert) but would it be possible for  
me to access the DB of a php app using a mysql database, from within my  
Rails app?

I want to install my (php) forums in [forum.site.com](http://forum.site.com), and my main site  
(using rails) will be at the root, [site.com](http://site.com) - so could I list the latest  
forum thread, in my Rails side of the site, by simply accessing the  
mysql database directly?

Guess I would just need to give it username/pw for the db, and the mysql  
query?

Is it going to be easy enough to do, or should I stick with a full php  
solution (can’t drop PHP as we need a full featured forum like vB).

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@ast](https://www.ruby-forum.com/u/ast)\
**Post date:** [April 20, 2010, 10:07pm UTC](https://www.ruby-forum.com/t/can-i-access-another-apps-mysql-database-with-my-rails-app/187268/2 "2010-04-20T22:07:32Z")

</div>

> mysql database directly?
> 
> Guess I would just need to give it username/pw for the db, and the  
> mysql  
> query?
> 
> Is it going to be easy enough to do, or should I stick with a full php  
> solution (can’t drop PHP as we need a full featured forum like vB).

That’s one way and would work fine. If the tables in the other  
database are at least somewhat AR friendly you can also setup the  
connection in database.yml (ie. with a name of say “phpforums”) and  
then create a model and use establish\_connection to point it to the  
phpforums database.

If you’re careful about how you use it, it should work fine.

---

<div class="post-metadata">

**Author:** ![ast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@ast](https://www.ruby-forum.com/u/ast)\
**Post date:** [April 20, 2010, 10:16pm UTC](https://www.ruby-forum.com/t/can-i-access-another-apps-mysql-database-with-my-rails-app/187268/3 "2010-04-20T22:16:04Z")

</div>

Philip H. wrote:

> > mysql database directly?
> > 
> > Guess I would just need to give it username/pw for the db, and the  
> > mysql  
> > query?
> > 
> > Is it going to be easy enough to do, or should I stick with a full php  
> > solution (can’t drop PHP as we need a full featured forum like vB).
> 
> That’s one way and would work fine. If the tables in the other  
> database are at least somewhat AR friendly you can also setup the  
> connection in database.yml (ie. with a name of say “phpforums”) and  
> then create a model and use establish\_connection to point it to the  
> phpforums database.
> 
> If you’re careful about how you use it, it should work fine.

Thanks Philip 🙂

Would you know if it is easy enough to share sessions with a forum app  
such as vbulletin?

---

<div class="post-metadata">

**Author:** ![ast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@ast](https://www.ruby-forum.com/u/ast)\
**Post date:** [April 20, 2010, 10:35pm UTC](https://www.ruby-forum.com/t/can-i-access-another-apps-mysql-database-with-my-rails-app/187268/4 "2010-04-20T22:35:40Z")

</div>

On Apr 20, 2010, at 1:16 PM, Ast J. wrote:

> > 
> 
> Would you know if it is easy enough to share sessions with a forum app  
> such as vbulletin?

Unlikely to be easy. But if the cookies are available and you’re  
willing to parse the information you could do whatever you want.

-philip

---

<div class="post-metadata">

**Author:** ![ast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@ast](https://www.ruby-forum.com/u/ast)\
**Post date:** [April 20, 2010, 10:47pm UTC](https://www.ruby-forum.com/t/can-i-access-another-apps-mysql-database-with-my-rails-app/187268/5 "2010-04-20T22:47:13Z")

</div>

Philip H. wrote:

> On Apr 20, 2010, at 1:16 PM, Ast J. wrote:
> 
> > > 
> > 
> > Would you know if it is easy enough to share sessions with a forum app  
> > such as vbulletin?
> 
> Unlikely to be easy. But if the cookies are available and you’re  
> willing to parse the information you could do whatever you want.
> 
> -philip

I can live with access to the db for now - long-term plan is to move  
everything to rails.

Thanks again for the replies.

Ast.
