blob: 2570b4f379765dee8c93a6a64b34e15b02bdbafd (
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
30
31
|
import MySQLdb
USER = "asdfus"
PASSWORD = "gTYgT&M6q"
DATABASE = "asdfus"
class db:
def __init__ (self):
self.conn = None
self.cursor = None
self.connect()
def connect (self):
self.conn = MySQLdb.connect (host = "localhost",
user = USER,
passwd = PASSWORD,
db = DATABASE
)
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()
|