Created
February 21, 2014 12:28
-
-
Save max107/9133414 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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