'''
数据库的-新增-更新-删除
'''
from pymysql import *
# import pymysql
def option_db():
try:
conn = connect(host='127.0.0.1', port=3306, user='root',passwd='root',
db='python03', charset='utf8')
cursor = conn.cursor()
sql = "insert into students('name') values('老王1');"
cursor.execute(sql)
sql = "insert into students('name') values('老王2');"
cursor.execute(sql)
# 提交事务
conn.commit()
cursor.close()
conn.close()
except Exception as e:
print('error')
# 部分提交 执行成功
# conn.commit()
# 回滚 银行转账
conn.rollback()
if __name__ == '__main__':
option_db()
Python新增数据到数据库
猜你喜欢
转载自blog.csdn.net/weixin_45905671/article/details/104097237
今日推荐
周排行