验证中...
语言: Python
分类: 编程语言基础
最后更新于 2018-08-16 15:47
mysqlclient
原始数据 复制代码
__author__ = 'webrx'
''' 演示python3.7 mysqlclient mysql8.0.12 crud操作'''
# https://www.cnblogs.com/itdyb/p/5700614.html
import MySQLdb
conn=MySQLdb.connect(host='127.0.0.1',port=3306,user='root',passwd='',db='zitdb',charset='utf8')
cursor=conn.cursor()
# cursor.execute('create table if not exists myt(i int)')
#cursor.execute("insert into myt values(10),(20),(30),(40)")
#conn.commit()
cursor.execute('select * from myt')
# print(cursor.fetchone())
# print(cursor.fetchmany(2))
#print(cursor.fetchall())
#print(cursor.rowcount)
try:
#cursor.execute(sql_insert)
#print(cursor.rowcount)
#cursor.execute(sql_update)
#print(cursor.rowcount)
#cursor.execute(sql_delete)
#print(cursor.rowcount)
cursor.execute('insert into myt values(100)')
# conn.commit()
except Exception as e:
print(e)
conn.rollback()
finally:
conn.commit()
cursor.close()
conn.close()
# print(conn)
# print(cursor)
#cursor.close()
#conn.close()

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助