Created
July 26, 2011 05:27
-
-
Save b1naryth1ef/1106039 to your computer and use it in GitHub Desktop.
MySQL using classes
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 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