-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
42 lines (36 loc) · 838 Bytes
/
database.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
# -*- coding: utf-8 -*-
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="123456tmc",
database="cross_language"
)
mycursor = mydb.cursor()
def insert(query, val):
mycursor.execute(query, val)
mydb.commit()
def execute_query(query):
mycursor.execute(query)
result = mycursor.fetchall()
return result
def execute_query1(query, val):
mycursor.execute(query, val)
result = mycursor.fetchall()
return result
def update(query):
mycursor.execute(query)
mydb.commit()
# import MySQLdb
#
# mydb = MySQLdb.connect("localhost", "root", "123456tmc", "cross_language")
# mycursor = mydb.cursor()
#
# def insert(query):
# mycursor.execute(query)
# mydb.commit()
#
# def execute_query(query):
# mycursor.execute(query)
# result = mycursor.fetchall()
# return result