Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys,os
- from models.DBHandler import DBHandler
- import MySQLdb
- from MySQLdb.cursors import DictCursor
- from DBHandler import DBHandler
- GET_USER = 'select * from users where id = %s'
- UPDATE_USER_NAME = 'update users set username = %s where id = %s'
- def oldway():
- con = MySQLdb.connect(host='127.0.0.1',user='uname',passwd='passwd',db='dbname',cursorclass=DictCursor)
- curs = con.cursor()
- curs.execute('select * from users where id = 4;')
- print 'Number of results %s' % curs.rowcount
- row = curs.fetchone()
- jason = dict()
- jason['id'] = row['id']
- jason['name'] = row['username']
- jason['age'] = row['age']
- jason['pets'] = []
- curs.execute('select pets.name as pet_name from pets join users on pets.user_id = users.id where users.id = %s;',jason['id'])
- for x in range(0,curs.rowcount):
- jason['pets'].append(curs.fetchone()['pet_name'])
- print jason
- def newway(uid):
- db = DBHandler(dhost='127.0.0.1',duser='uname',dpass='passwd',dbname='dbname',cursor='DictCursor')
- db.execute(UPDATE_USER_NAME,("bagger",4))
- vinny = db.getrow(GET_USER,uid)
- print vinny
- if __name__ == '__main__':
- newway(4)
Add Comment
Please, Sign In to add comment