python mysql查询更新

葫芦的运维日志

浏览量 6397 2018/01/03 02:30

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/110-mysql查询更新

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

打赏

留言板

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

© 冰糖葫芦甜(bthlt.com) 2025 王梓打赏联系方式陕ICP备17005322号-1