Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import MySQLdb
- import MySQLdb.cursors
- class Client:
- __cursor = None
- def __init__(self, host, dbName, user, password, charset='utf8'):
- con = MySQLdb.connect(host, dbName, user, password, charset=charset, cursorclass=MySQLdb.cursors.DictCursor)
- self.__cursor = con.cursor()
- pass
- def query(self, sql, params=None):
- if params is not None:
- if type(params) is not tuple and type(params) is not list :
- params = (params,)
- for value in params :
- sql = sql.replace("?", "'" + str(value) + "'", 1)
- self.__cursor.execute(sql)
- return self.__cursor.fetchall()
- def getProjectByID(self, id):
- res = self.query("SELECT * FROM projects WHERE id=?", id)
- if len(res) :
- return res[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement