0

I have two applications called app1 & app2, I have connected two database using connection establish method. I have same table name in both the databases, now I want to send selected data from app2 to app1. Here is my code for connecting two databases, please help me on this.

   class Student < ActiveRecord::Base

   establish_connection :adapter  => "mysql2",

                   :database => "app1_db",

                   :username => "root",

                   :password => "root"

     set_table_name "students" 

     belongs_to :student, :class_name => "students", :foreign_key => "fk_student_id"

     end
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
Pavan
  • 1
  • 2
  • 1
    So? What is the problem? – Rajesh Kolappakam Sep 13 '13 at 05:47
  • 1
    It is *extremely* dangerous to set up something like this. You should have them communicate over some sort of REST API. – Tim Dorr Sep 13 '13 at 05:50
  • You can use API for that. – Bachan Smruty Sep 13 '13 at 05:57
  • I have successfully connected two databases using connection establish method, i have connected two tables from different databases. but i am not able to restrict the data copying from one table to another table. i want to send selected data from app2 to app1, but now its copying all data from app2 to app1 – Pavan Sep 13 '13 at 06:11

1 Answers1

1

in the establish_connection section you may need to provide the host name.

if you want to create two different connection use this query

    client_1 = Mysql2::Client.new(
               :host => HOST, 
               :username => USER_NAME,            
               :encoding => "utf8", 
               :reconnect => false, 
               :database => DATA_BASE,
               :pool => "250", 
               :password => PASSWORD)

also same create one client_2 connection and write your query

Debadatt
  • 5,935
  • 4
  • 27
  • 40
Sabyasachi Ghosh
  • 2,765
  • 22
  • 33
  • I want to send selected data from one database to another database – Pavan Sep 13 '13 at 05:53
  • as i am beginner to ROR , so i am not able to understand , could you please share one example – Pavan Sep 13 '13 at 05:57
  • please check https://github.com/brianmario/mysql2 first and let me know if there is any doubts – Sabyasachi Ghosh Sep 13 '13 at 06:00
  • I have successfully connected two databases using connection establish method, i have connected two tables from different databases. but i am not able to restrict the data copying from one table to another table. i want to send selected data from app2 to app1, but now its copying all data from app2 to app1 – Pavan Sep 13 '13 at 06:05
  • for validation you need to add methods and need to provide logic on that method only. – Sabyasachi Ghosh Sep 13 '13 at 06:40