summaryrefslogtreecommitdiff
path: root/pb/lib/Db/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'pb/lib/Db/__init__.py')
-rw-r--r--pb/lib/Db/__init__.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/pb/lib/Db/__init__.py b/pb/lib/Db/__init__.py
new file mode 100644
index 0000000..91b0fcf
--- /dev/null
+++ b/pb/lib/Db/__init__.py
@@ -0,0 +1,55 @@
+import MySQLdb
+import time
+USER = "asdfus"
+PASSWORD = "gTYgT&M6q"
+DATABASE = "asdfus"
+
+class Db(object):
+ 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 self.conn.insert_id()
+
+ def insert_cmd (
+ self,
+ date=time.time(),
+ remote_addr="NULL",
+ username="NULL",
+ url="NULL",
+ directory="NULL",
+ oldfile="NULL",
+ newfile="NULL",
+ cmd="NULL",
+ dataobj="NULL",
+ tag="NULL"):
+ try:
+ sql = "INSERT INTO im_cmd "
+ sql += "(date, remote_addr, name, url, dir, oldfile, newfile, cmd, dataobj, tag) "
+ sql += "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
+ #or "NULL"
+ args = (date, remote_addr, username, url, directory, oldfile, newfile, cmd, dataobj, tag)
+ #args = (now(), os.environ['REMOTE_ADDR'], name, url, dir, oldfile, newfile, " ".join(cmd),dataobj)
+ self.execute(sql, args)
+ except Exception as e:
+ sys.stderr.write(str(e))
+ return