创建Connection连接 ,必要时实现rollback

# from pymysql import connect

# #创建Connection连接

# conn = connect(host = 'localhost',port = 3306,user = 'root' ,password = 'hezhuang',database = 'TCL',charset = 'utf8')

# #  获得Cursor对象

# cursor = conn.cursor()

# count = cursor.execute('select * from goods;')

# print('查询到%d条数据'%count)

# print(cursor.fetchone())

# print(cursor.fetchone())

# print(cursor.fetchone())

# print(cursor.fetchone())

# print(cursor.fetchmany())#获取一条

# print(cursor.fetchmany(3))#传人几条获取几条

# print(cursor.fetchall())

# #关闭Cursor对象

# cursor.close()

# conn.close()




# from pymysql import connect

# # #创建Connection连接

# conn = connect(host = 'localhost',port = 3306,user = 'root' ,password = 'hezhuang',database = 'TCL',charset = 'utf8')

# # #  获得Cursor对象

# cursor = conn.cursor()

# # print(cursor.execute(''' into goods_cates(name) value("硬盘1")'''))

# # print(cursor.execute(''' into goods_cates(name) value("硬盘2")'''))

# # print(cursor.execute(''' into goods_cates(name) value("硬盘3")'''))

# conn.commit()

# #报错原因是

# #双引号嵌套,可以使用三个引号。来代表完整字符串

# print(cursor.execute(''' into goods_cates(name) value("硬盘3")'''))

# print(cursor.execute(''' into goods_cates(name) value("硬盘4")'''))

# #假如执行代码有错时可以先执行

# conn.rollback()

# #重新回滚

# print(cursor.execute(''' into goods_cates(name) value("硬盘4")'''))

# conn.commit()

#报错原因是

#双引号嵌套,可以使用三个引号。来代表完整字符串

你可能感兴趣的:(创建Connection连接 ,必要时实现rollback)