Without a Gem, you can achieve this with the Ruby script itself
I assumed that you have a rails application, you can create a rake task to retrieve data from a WordPress database
Step 1:
value = {host: "192.*.*.*", username: '', password: '', database: ''} ActiveRecord::Base.establish_connection( adapter: 'mysql2', encoding: 'utf8', pool: 5, host: value[:host], username: value[:username], password: value[:password], database: value[:database] )
Step 2:
Then you need to define the database tables
database_tables = {:"database_name" => ["SaveContactForm7_1", "SaveContactForm7_2","SaveContactForm7_3","SaveContactForm7_4"]}
Step 3:
tables = database_tables[key] Key refers to the database name
Step 4:
tables.each do |table| MODEL_CLASS= table Object.const_set(MODEL_CLASS, Class.new(ActiveRecord::Base) { def self.name() MODEL_CLASS end;def self.table_name() MODEL_CLASS end }) records = MODEL_CLASS.constantize.all results = [] records.each do |record| set = {} columns = MODEL_CLASS.constantize.column_names p columns columns.each do |column| p record.send(column.to_sym) p set[:mobile] = record.send(column.to_sym) end results << set p record end p "Task done...." p results end
As a result, you can see an array of hashes. you can insert into your active record models
Please feel free to give your suggestion for this.
source share