Skip to content

Instantly share code, notes, and snippets.

@max107
Created February 21, 2014 12:28
Show Gist options
  • Save max107/9133414 to your computer and use it in GitHub Desktop.
Save max107/9133414 to your computer and use it in GitHub Desktop.
import os
import sys
import MySQLdb
MYSQL_HOST = "localhost"
MYSQL_USER = "testuser"
MYSQL_PASSWORD = "testpass"
MYSQL_DB = "test"
def get_mysql_connect():
"""
Return mysql connection
"""
return MySQLdb.connect(host=MYSQL_HOST, user=MYSQL_USER, passwd=MYSQL_PASSWORD, db=MYSQL_DB)
def query(query, *args):
"""
Run mysql query and return data from mysql
"""
cursor = get_mysql_connect.cursor()
cursor.execute(query, *args)
return cursor.fetchall()
def main():
result = 0
for item in query("SELECT * FROM users"):
result += item.something
return result
if __name__ == "__main__":
out = main()
print(out)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment