python常用sql语句

 #coding=utf-8
import MySQLdb
conn = MySQLdb.Connect(host = '127.0.0.1',port=3306,user='root',passwd='',db='test',charset='utf8')
cursor = conn.cursor() try:
#插入数据
sql_insert = "insert into orders(order_id,product_id) values (777,777)"
cursor.execute(sql_insert)
print cursor.rowcount #修改数据
sql_update = "update orders set order_id = 99999 where id=12"
cursor.execute(sql_update)
print cursor.rowcount #删除数据
sql_delete = "delete from orders where id = 3"
cursor.execute(sql_delete)
print cursor.rowcount #提交
conn.commit()
except Exception as e:
print e
conn.rollback() #关闭指针和连接
cursor.close()
conn.close()
上一篇:构建ASP.NET网站十大必备工具(1)


下一篇:universal image loader自己使用的一些感受