【发布时间】:2023-02-09 00:26:29
【问题描述】:
我有一个数据库,当我查询一个表时,我得到 67 个结果。 SQL 是:
SELECT lower(UserName) from Participants ;
我尝试连接到数据库,但没有出现连接错误。
def db_connect ():
try:
cnx = mysql.connector.connect(user=db_user, password=db_password,host=db_host,database=db_name)
return cnx
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
def main():
cnx = db_connect()
cursor = cnx.cursor()
query = ("SELECT lower(UserName) from Participants ;")
cursor.execute(query)
print(cursor.rowcount)
它为行数打印出 -1。与数据库的连接似乎正常工作,SQL 是一个简单的查询...
【问题讨论】:
标签: python mysql sql mysql-connector