Skip to content

Instantly share code, notes, and snippets.

@b1naryth1ef
Created July 26, 2011 05:27
Show Gist options
  • Select an option

  • Save b1naryth1ef/1106039 to your computer and use it in GitHub Desktop.

Select an option

Save b1naryth1ef/1106039 to your computer and use it in GitHub Desktop.
MySQL using classes
import MySQLdb
user = "root"
passwd = ""
db = "test"
host = "localhost"
DB = MySQLdb.connect(user=user, passwd=passwd, host=host, db=db)
C = DB.cursor()
class User(object):
def __init__(self, userid, username=None, email=None, password=None, date=None):
self.id = userid
self.username = username
self.email = email
self.password = password
self.date = date
def find(field,value)
x = []
c.execute("""SELECT * FROM users WHERE %s = '%s' """ % (field, value))
for id, username, email, password, date in c.fetchall():
u = User(id,username,email,password,date)
x.append(u)
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment