You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
5 years ago
|
import pymysql
|
||
|
|
||
|
def select(sql):
|
||
|
conn = pymysql.connect(host='localhost',user='root', passwd='123456', charset='utf8')
|
||
|
cursor = conn.cursor()
|
||
|
conn.select_db('goods')
|
||
|
# -----------Begin----------
|
||
|
# 请在下面输入查询数据的语句,完成相应功能
|
||
|
command = sql
|
||
|
cursor.execute(command)
|
||
|
# 请在下面输入获取数据的语句,完成相应功能
|
||
|
records = cursor.fetchall()
|
||
|
# ------------End-----------
|
||
|
# 关闭数据库连接
|
||
|
cursor.close()
|
||
|
conn.close()
|
||
|
return records
|
||
|
|
||
|
def delete(sql):
|
||
|
conn = pymysql.connect(host='localhost',user='root', passwd='123456', charset='utf8')
|
||
|
cursor = conn.cursor()
|
||
|
conn.select_db('goods')
|
||
|
# -----------Begin----------
|
||
|
# 请在下面输入查询数据的语句,完成相应功能
|
||
|
command = sql
|
||
|
cursor.execute(command)
|
||
|
# 请在下面输入获取数据的语句,完成相应功能
|
||
|
|
||
|
# ------------End-----------
|
||
|
# 提交数据到数据库
|
||
|
conn.commit()
|
||
|
# 关闭数据库连接
|
||
|
cursor.close()
|
||
|
conn.close()
|
||
|
|
||
|
|
||
|
def alter(sql):
|
||
|
conn = pymysql.connect(host='localhost', user='root', passwd='123456', charset='utf8')
|
||
|
cursor = conn.cursor()
|
||
|
conn.select_db('goods')
|
||
|
|
||
|
|
||
|
command=sql
|
||
|
cursor.execute(command)
|
||
|
|
||
|
# 提交数据到数据库
|
||
|
conn.commit()
|
||
|
# 关闭数据库连接
|
||
|
cursor.close()
|
||
|
conn.close()
|