Class: Mysqlcollector::Mysql
Instance Method Summary collapse
- #close ⇒ Object
- #execute(sql) ⇒ Object
-
#initialize ⇒ Mysql
constructor
A new instance of Mysql.
Constructor Details
#initialize ⇒ Mysql
Returns a new instance of Mysql.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mysqlcollector/mysql.rb', line 5 def initialize @conn = Mysql2::Client.new(host: $config[:mysql_host], port: $config[:mysql_port], username: $config[:mysql_username], password: $config[:mysql_password]) Mysqlcollector::Log.new.debug("Connected on MySQL server: #{$config[:mysql_host]}:#{$config[:mysql_port]}"); rescue Exception => error Mysqlcollector::Log.new.error(error.) end |
Instance Method Details
#close ⇒ Object
26 27 28 29 30 |
# File 'lib/mysqlcollector/mysql.rb', line 26 def close @conn.close rescue exit 1 end |
#execute(sql) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/mysqlcollector/mysql.rb', line 16 def execute(sql) begin Mysqlcollector::Log.new.debug("MySQL Query: #{sql}") @conn.query(sql).each(:as => :hash) rescue Exception => error Mysqlcollector::Log.new.sql_error(error, sql); end end |