Method: WIKK::SQL#connect
- Defined in:
- lib/wikk_sql.rb
#connect(db_config) {|[]| ... } ⇒ NilClass, WIKK_SQL Also known as: open
Set up the mySQL connection.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/wikk_sql.rb', line 36 def connect(db_config) if db_config.class == Hash sym = db_config.each_with_object({}) { |(k,v),h| h[k.to_sym] = v } db_config = Struct.new(*(k = sym.keys)).new(*sym.values_at(*k)) end begin @my = Mysql::new(db_config.host, db_config.dbuser, db_config.key, db_config.db ) rescue Exception => e @my = nil raise e end raise Mysql::Error, 'Not Connected' if @my == nil #@@my.reconnect = true if block_given? yield return close end return @my end |