Skip to content

Instantly share code, notes, and snippets.

@maxivak
Created October 20, 2012 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxivak/3924988 to your computer and use it in GitHub Desktop.
Save maxivak/3924988 to your computer and use it in GitHub Desktop.
Dynamic connection to MySQL database in Ruby on Rails (mysql2)
require 'mysql2'
db = Mysql2::Client.new(:host => 'localhost', :username => 'root', :password=> 'password', :database => 'db_name' )
res = db.query("select * from users")
res.each do |row|
col1 = row['id']
col2 = row['email']
..
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment