Calcifer Calcifer 2
Python

mysql查询更新

2018/01/03 02:30 6479 次阅读 王梓
打赏
✸ ✸ ✸
from django.db import connection

##  查询接口  ##
def cursorQuery( sql, parlist):
    cursor = connection.cursor()
    try:
        cursor.execute(sql, parlist)
    except Exception, e:
        print "Catch exception : " + str(e)
    return cursor.fetchall()

## 更新接口 ##
def cursorUpdate(sql,parlist):
    cursor = connection.cursor()
    try:
        # 执行sql语句
        cursor.execute(sql,parlist)
        # 提交到数据库执行
        connection.commit()
    except:
        # 发生错误时回滚
        connection.rollback()

    # 关闭数据库连接
    connection.close()
✸ ✸ ✸

📜 版权声明

本文作者:王梓 | 原文链接:https://www.bthlt.com/note/4062297-Pythonmysql查询更新

出处:葫芦的运维日志 | 转载请注明出处并保留原文链接

📜 留言板

留言提交后需管理员审核通过才会显示