Skip to content

Instantly share code, notes, and snippets.

@llaskin
Last active December 10, 2015 19:48
Show Gist options
  • Save llaskin/4484044 to your computer and use it in GitHub Desktop.
Save llaskin/4484044 to your computer and use it in GitHub Desktop.
def get_active_site_name
require 'pp'
require 'mysql2'
connection = Mysql2::Client.new(:host => "myhost", :username => 'myuser', :password => 'mypass')
insert_statement = "select value from db.table where key_name = 'foo';"
result = connection.query(insert_statement, :as => :array)
connection.close
pp result.to_a #result A below
pp result.to_a.flatten #result B below
pp result.to_a.flatten.to_s #result C
pp result.to_a.first
##A: [["llaskin"]]
##B: ["llaskin"]
##C: "[\"llaskin\"]"
##D: ["Automation Test Same Shard01-07-2013--11-59-40 Site"]
end
#db.table structure:
#key_name(varchar 45) | value(varchar 1024)
#'foo' | 'llaskin'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment