Advertisement
Guest User

Untitled

a guest
Feb 6th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import MySQLdb
  4. import MySQLdb.cursors
  5.  
  6. class Client:
  7.     __cursor = None
  8.  
  9.     def __init__(self, host, dbName, user, password, charset='utf8'):
  10.         con = MySQLdb.connect(host, dbName, user, password, charset=charset, cursorclass=MySQLdb.cursors.DictCursor)
  11.         self.__cursor = con.cursor()
  12.  
  13.         pass
  14.  
  15.     def query(self, sql, params=None):
  16.         if params is not None:
  17.             if type(params) is not tuple and type(params) is not list :
  18.                 params = (params,)
  19.  
  20.             for value in params :
  21.                 sql = sql.replace("?", "'" + str(value) + "'", 1)
  22.  
  23.         self.__cursor.execute(sql)
  24.  
  25.         return self.__cursor.fetchall()
  26.  
  27.     def getProjectByID(self, id):
  28.         res = self.query("SELECT * FROM projects WHERE id=?", id)
  29.  
  30.         if len(res) :
  31.             return res[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement