gpt4 book ai didi

python - 属性错误: '_mysql.connection' object has no attribute 'cursor'

转载 作者:行者123 更新时间:2023-11-29 10:16:28 51 4
gpt4 key购买 nike

我正在尝试将程序从 python 2 转换为 python 3。我在程序中设置的 MYSQL 数据库必须更新。我遇到了与 this one 非常相似的问题,但我不明白如何将我的对象从“连接”更改为“连接”,因为 Python 中没有强制转换

这是我的代码:

import _mysql as mc

db = mc.connect (host = "localhost", user = "root", passwd = "password1234")
cursor = db.cursor()

它看起来是正确的,但由于某种原因 connect() 函数返回一个“连接”对象而不是“连接”。如有任何帮助,我们将不胜感激。

最佳答案

对于mysqlclient

import MySQLdb

不要使用_mysql,因为它是low level interface and does not include all the methods

关于python - 属性错误: '_mysql.connection' object has no attribute 'cursor' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50053995/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com