forked from Maru-zhang/iCCUT-Backend-Flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.py
56 lines (47 loc) · 1.72 KB
/
mysql.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
__author__ = 'Maru'
#coding=gb2312
import MySQLdb
class Mysql:
host = 'localhost'
port = 3306
user = 'root'
pwd = ''
def __init__(self):
self.conn = MySQLdb.connect(host=self.host,user=self.user,passwd=self.pwd,db='sy_video',port=self.port,charset='gb2312')
self.conn.set_character_set('gb2312')
self.cur = self.conn.cursor()
def insertNewsData(self,result):
try:
sql = 'insert INTO FreeNews VALUE ("%s","%s","%s")' % result
self.cur.execute(sql)
self.conn.commit()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
def queryAllData(self):
try:
sql = 'select * from FreeVideo'
self.cur.execute(sql)
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
def insertData(self,id,title,url,leve1,leve2):
try:
sql = 'insert into FreeVideo values(%d,"%s","%s","%s","%s")' % (id,title,url,leve1,leve2)
print(sql)
self.cur.execute(sql)
self.conn.commit()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
def insertNews(self,id,title,url,time):
try:
sql = 'insert into FreeVideo values(%d,"%s","%s","%s")' % (id,title,time,url,)
print(sql)
self.cur.execute(sql)
self.conn.commit()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
def queryData(self,sql):
try:
self.cur.execute(sql)
self.conn.commit()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])