python mysql connection close,Python数据库连接关闭

编程入门 行业动态 更新时间:2024-10-11 03:22:43

python mysql connection close,Python<a href=https://www.elefans.com/category/jswz/34/1771108.html style=数据库连接关闭"/>

python mysql connection close,Python数据库连接关闭

Using the code below leaves me with an open connection, how do I close?

import pyodbc

conn = pyodbc.connect('DRIVER=MySQL ODBC 5.1 driver;SERVER=localhost;DATABASE=spt;UID=who;PWD=testest')

csr = conn.cursor()

csr.close()

del csr

解决方案

Connections have a close method as specified in PEP-249 (Python Database API Specification v2.0):

import pyodbc

conn = pyodbc.connect('DRIVER=MySQL ODBC 5.1 driver;SERVER=localhost;DATABASE=spt;UID=who;PWD=testest')

csr = conn.cursor()

csr.close()

conn.close() #

Since the pyodbc connection and cursor are both context managers, nowadays it would be more convenient (and preferable) to write this as:

import pyodbc

conn = pyodbc.connect('DRIVER=MySQL ODBC 5.1 drive

更多推荐

python mysql connection close,Python数据库连接关闭

本文发布于:2024-03-06 09:58:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1715044.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库连接   mysql   python   connection   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!