Created
December 1, 2015 05:39
-
-
Save anil826/344040a2d820bf58ce15 to your computer and use it in GitHub Desktop.
piwi database using ruby in rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql' | |
module Piwik | |
#--------------query for piwik database for getting token of user----------- | |
def piwik_tokens | |
!connection_piwik.nil? ? @rs = connection_piwik.query('select login, token_auth from enbake_piwik_user;') : "#{["Connect-Piwik-Sever"]}" | |
!@rs.nil? ? result : ["Connect-Piwik-Sever"] | |
end | |
#--------------------query for site_ids for clients dashboard---------------- | |
def piwik_site_ids | |
!connection_piwik.nil? ? @rs = connection_piwik.query("select name, idsite from enbake_piwik_site;") : "#{["Connect-Piwik-Sever"]}" | |
!@rs.nil? ? result : ["Connect-Piwik-Sever"] | |
end | |
#----------------creating connection for piwik database with mysql adapter------- | |
private | |
def connection_piwik | |
Mysql.new('localhost', 'root', 'a', 'enbake') | |
rescue Mysql::Error => e | |
# Print the error. | |
puts "ERROR #{e.errno} (#{e.sqlstate}): #{e.error}" | |
puts "Can't connect to the MySQL database specified." | |
# Signal an error | |
ensure | |
end | |
#---------------------------data for dropdown----------------------- | |
def result | |
@data = Array.new | |
@rs.each do |f| | |
f[0] = "#{f[0]}-#{f[1]}" | |
@data = @data << f | |
end | |
connection_piwik.close | |
@data | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment