Skip to content

Instantly share code, notes, and snippets.

@azyobuzin
Created November 2, 2012 12:23
Show Gist options
  • Save azyobuzin/4001017 to your computer and use it in GitHub Desktop.
Save azyobuzin/4001017 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import MySQLdb
from wop_core import *
class MySqlWrapping:
def __init__(self):
self.db = MySQLdb.connect(user = db_name, passwd = db_password, db = db_name, charset = "utf8")
self.c = db.cursor()
def execute(self, query, args = None):
self.c.execute(query, args)
def fetchone(self, query, args = None):
self.execute(query, args)
return self.c.fetchone()
def fetchall(self, query, args = None):
self.execute(query, args)
return self.c.fetchall()
def commit(self):
self.db.commit()
def close(self):
self.c.close()
self.db.close()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment