datadb.py 782 Bytes
  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
# -*- coding: utf-8 -*-
import MySQLdb

class DataDB():
def __init__(self):
self.init_database()

def init_database(self):
#mysqlHost = '192.168.20.61'
mysqlHost = 'data2.piki.work'
UserName = 'pikids'
mysqlPassword = 'zmfflr2715'
DBName = 'piki_data_dashboard'
self.db = MySQLdb.connect(host=mysqlHost, user=UserName, passwd=mysqlPassword, db=DBName)
self.db.set_character_set('utf8')
#charset = self.db.character_set_name()
self.cursor = self.db.cursor(MySQLdb.cursors.DictCursor)

def fb_insert(self,sql):
#print sql
self.cursor.execute(sql)
try :
self.db.commit()
except Exception, e:
print e
return -1
return