Skip to content

Instantly share code, notes, and snippets.

@wok
Created November 15, 2011 19:02
Show Gist options
  • Save wok/1367987 to your computer and use it in GitHub Desktop.
Save wok/1367987 to your computer and use it in GitHub Desktop.
ActiveRecord MULTI_STATEMENTS with mysql2
# 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