Python 个使用 pymysql 1.0.2 版本 无法使用 execute 函数

本贴最后更新于 1392 天前,其中的信息可能已经东海扬尘

Python个使用pymysql 1.0.2版本 无法使用execute函数

环境:Python 3.8 pymysql1.0.2版本

代码如下:

import pymysql con = pymysql.connect(host=host, port=port, user=user, password=password charset='utf8') sql= 'SELECT * FROM * LIMIT 5;' with con as cur: cur.execute(sql) res = cur.fetchall() cur.close() print(res)

确认数据库能正常连接,与sql查询语句正常,运行时错误如下:

AttributeError: 'Connection' object has no attribute 'execute'

  • 待分类
    9731 引用 • 916 回帖 • 5 关注
  • Q&A
    766 引用 • 583 回帖 • 2 关注
1 回帖
请输入回帖内容 ...
  • Song

    已找到原因,更新后的pymysql无法使用使用上下文管理器with, 直接使用创建游标cursor().execute(sql)就可以执行。