Skip to content

Instantly share code, notes, and snippets.

@JoshvaR88
Forked from wok/multi_statements_mysql2.rb
Last active August 29, 2015 14:16
Show Gist options
  • Save JoshvaR88/d87dea2908294269c055 to your computer and use it in GitHub Desktop.
Save JoshvaR88/d87dea2908294269c055 to your computer and use it in GitHub Desktop.
# place in config/initalizers
module ActiveRecord
class Base
# Establishes a connection to the database that's used by all Active Record objects.
def self.mysql2_connection(config)
config[:username] = 'root' if config[:username].nil?
if Mysql2::Client.const_defined? :FOUND_ROWS
config[:flags] = Mysql2::Client::FOUND_ROWS | Mysql2::Client::MULTI_STATEMENTS
end
client = Mysql2::Client.new(config.symbolize_keys)
options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment