summaryrefslogtreecommitdiff
path: root/impattern/im/cgi-bin/db.py
blob: 4da7b838f18643d99bb74340ed564cceb9d7907f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import MySQLdb
import time

def now ():
        return int(time.mktime(time.localtime()))
class db:
        def __init__ (self):
                self.conn = None
                self.cursor = None
                self.connect()

        def connect (self):
                self.conn = MySQLdb.connect (host = "127.0.0.1",
          user = "asdfus",
          passwd = "gTYgT&M6q",
                                        db = "asdfus")
                self.cursor = self.conn.cursor ()

        def execute (self,sql,args=()):
                try:
                        self.cursor.execute(sql,args)
                except MySQLdb.Error, e:
                        print "Error %d: %s" % (e.args[0], e.args[1])
                        # sys.exit (1)
                        self.connect()
                        self.cursor.execute(sql,args)

        def lastinsertid (self):
                return DB.conn.insert_id()