Ruby version: 1.9.1 Mysql version: 5.0
code written was:
require \"rubygems\"
require \"active_record\"
puts \"1\"
class Source <
Finally, after putting all my efforts with MySql and Postgresql, I am able to make successful connection with MySql.
Working set involves:
Ruby Version: 1.87
MySql Version: 5.5
To work with ActiveRecord, one need to have the adapter installed. On command prompt, write:
gem install mysql2.
Code to build successful connection of MySql database with Ruby under the layer of ActiveRecord:
require "rubygems"
require "active_record"
class Source < ActiveRecord::Base
set_table_name "sources"
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "localhost",
:username => "test",
:password => "test",
:port => 3306,
:database => "TestDB",
:socket => "mysql"
)
end
source = Source.find(:first, :conditions => [ "source_id = ?", 2 ])
puts source.source_name
Note: Adapter used is mysql2 and not mysql