gpt4 book ai didi

mysql - python查询mysql添加结果到下拉选择?

转载 作者:行者123 更新时间:2023-11-30 00:45:17 24 4
gpt4 key购买 nike

尝试开发一些代码,以便在按下按钮时我可以返回 information_Schema 的内容并允许自己从生成的列表中选择一个数据库,创建按钮并请求登录不是问题并且有效,然而返回结果失败,到目前为止我创建的代码是这样的:

def mysqlConnect():
import pymysql
import subprocess
sqlUsr = MysqlUsr.get()
sqlpwd = Mysqlpwd.get()
conn = pymysql.connect(host='192.168.0.27', user= sqlUsr, passwd=sqlpwd, db='information_schema')
cursor = conn.cursor()
conn.query("SELECT SCHEMA_NAME FROM SCHEMATA")
data = cursor.fetchall()
print (data)

data = conn.fetchall() 似乎给出了与括号 () 相关的错误,因为代码中必须首先处理它,但我不这样做明白为什么,我见过的所有例子都有这个语法吗?我想我需要将 schema_name 中的行放入元组中,以便我可以将该信息用作“下拉”选择框?有人做过类似的事情吗?在返回行之前我无法创建下拉列表,目前我只能返回行数,因为 fetchall() 命令失败。

Exception in Tkinter callback Traceback (most recent call last):
File "C:\Python33\lib\tkinter_init_.py", line 1475, in
call return self.func(*args)
File "S:\python\jon\wrt_toolkit_v5\wrt_toolkit_v6.py", line 97, in
mysqlConnect data = cursor.fetchall()
File "C:\Python33\lib\site-packages\pymysql3-0.4-py3.3.egg\pymysql\cursors.py", line 194,
in fetchall self._check_executed()
File "C:\Python33\lib\site-packages\pymysql3-0.4-py3.3.egg\pymysql\cursors.py", line 64,
in _check_executed self.errorhandler(self, ProgrammingError, "execute() first")
File "C:\Python33\lib\site-packages\pymysql3-0.4-py3.3.egg\pymysql\connections.py", line 184,
in defaulterrorhandler raise errorclass(errorvalue)
pymysql.err.ProgrammingError: execute() first

最佳答案

您需要在调用fetch_all之前调用cursor.execute(query, args=None)

关于mysql - python查询mysql添加结果到下拉选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21430396/

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