博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python常用sql语句
阅读量:4578 次
发布时间:2019-06-08

本文共 785 字,大约阅读时间需要 2 分钟。

1 #coding=utf-8 2 import MySQLdb 3 conn = MySQLdb.Connect(host = '127.0.0.1',port=3306,user='root',passwd='',db='test',charset='utf8') 4 cursor = conn.cursor() 5  6 try: 7     #插入数据 8     sql_insert = "insert into orders(order_id,product_id) values (777,777)" 9     cursor.execute(sql_insert)10     print cursor.rowcount11 12     #修改数据13     sql_update = "update orders set order_id = 99999 where id=12"14     cursor.execute(sql_update)15     print cursor.rowcount16 17     #删除数据18     sql_delete = "delete from orders where id = 3"19     cursor.execute(sql_delete)20     print cursor.rowcount21 22     #提交23     conn.commit()24 except Exception as e:25     print e26     conn.rollback()27     28 #关闭指针和连接29 cursor.close()30 conn.close()

 

转载于:https://www.cnblogs.com/gide/p/4771786.html

你可能感兴趣的文章
差点搞不懂快排
查看>>
STM32学习之路入门篇之指令集及cortex——m3的存储系统
查看>>
Linux 任务计划:crontab
查看>>
JPA用法中字段起名规范
查看>>
http status code
查看>>
input宽度超出
查看>>
java设计模式----工厂方法模式
查看>>
ubuntu下配置安装Myslq
查看>>
phpstudy打不开localhost(Apache)
查看>>
Python实现读取json文件到excel表
查看>>
Opengl_入门学习分享和记录_02_渲染管线(一)顶点着色器&片段着色器
查看>>
[USACO07DEC]Sightseeing Cows
查看>>
什么是网站CDN服务,CDN加速原理?
查看>>
内存泄漏以及常见的解决方法
查看>>
解决itunesconnect无法訪问
查看>>
Java使用OkHttps工具类调用外部接口
查看>>
专题-HTTP
查看>>
寻找“水王”
查看>>
GAT2.0使用文档(组合接口测试)
查看>>
QString 和std::string互转
查看>>