验证中...
Languages: Python
Categories: 编程语言基础
Latest update 2018-12-09 10:33
mysqlclient
Raw Copy
__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()

Comment list( 0 )

You need to Sign in for post a comment

Help Search