-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsql.py
40 lines (35 loc) · 1.16 KB
/
sql.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
import pymysql.cursors
import pymysql
# from pymysql import err
db = pymysql.connect(
host = 'localhost',
user = 'root',
password = '123456',
db = 'xhs',
cursorclass=pymysql.cursors.DictCursor
)
def insert_notes_id(note_id,uid, kw):
with db.cursor() as cursor:
sql = 'INSERT INTO `notes_id_tab`(`note_id`, `uid`, `kw`) VALUES (%s, %s, %s)'
try:
cursor.execute(sql,(note_id, uid, kw))
db.commit()
except:
db.rollback()
def get_note_id():
with db.cursor() as cursor:
sql = 'SELECT `note_id` ,`kw` FROM `notes_id_tab`'
try:
cursor.execute(sql)
data = cursor.fetchall()
return data
except:
db.rollback()
def insert_notes_info(note_id, content, uid, likes, share, star, comment, kw):
with db.cursor() as cursor:
sql = 'INSERT INTO `notes_info_tab`(`id`, `content`, `uid`, `likes`, `share`, `star`,`comment`,`kw`) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)'
try:
cursor.execute(sql, (note_id, content, uid, likes, share, star, comment, kw))
db.commit()
except:
db.rollback()