forked from roberthsu2003/python-SQLite-MySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleted.py
35 lines (29 loc) · 945 Bytes
/
deleted.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
import pymysql.cursors
from pymysql import Error
def create_connection():
connection = None
try:
connection = pymysql.connect(host='localhost',
user='root',
password='1234',
database='world',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
except Error as e:
print(e)
return connection
def delete_task(conn, id):
sql = 'DELETE FROM task WHERE id=%s'
with conn.cursor() as cursor:
cursor.execute(sql,(id,))
conn.commit()
def delete_all_task(conn):
sql = 'DELETE FROM task'
with conn.cursor() as cursor:
cursor.execute(sql)
conn.commit()
if __name__ == "__main__":
conn = create_connection()
if conn is not None:
with conn:
delete_task(conn, 2)