Python 如何将MySQL数据库连接到输入函数

Python 如何将MySQL数据库连接到输入函数,python,mysql,Python,Mysql,我正在构建一个程序,用户在其中输入企业名称以运行代码 我希望用户在下拉列表中选择企业名称,但目前我没有GUI使其正常工作 现在,我想将输入函数连接到SQL数据库企业名称列 我已经将SQL连接到我的python代码。。。但是如何将MySQL连接到输入函数?我希望用户能够从数据库中获取信息 我的SQL连接: import mysql.connector mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passp

我正在构建一个程序,用户在其中输入企业名称以运行代码

我希望用户在下拉列表中选择企业名称,但目前我没有GUI使其正常工作

现在,我想将输入函数连接到SQL数据库企业名称列

我已经将SQL连接到我的python代码。。。但是如何将MySQL连接到输入函数?我希望用户能够从数据库中获取信息

我的SQL连接:

import mysql.connector

mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM listedatabase.entreprises_inspecteurs")

for row in mycursor.fetchall():
    print (row[1])

mydb.close()

enterprise_name = input()
 mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

    mycursor = mydb.cursor()

    enterprise_name = input()
    mycursor.execute("SELECT n_fabricant FROM listedatabase.entreprises_inspecteurs", (enterprise_name,))
    data = mycursor.fetchall()
    if data:
        code goes there
    else: 
        print('data not found in database')
python:

import mysql.connector

mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM listedatabase.entreprises_inspecteurs")

for row in mycursor.fetchall():
    print (row[1])

mydb.close()

enterprise_name = input()
 mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

    mycursor = mydb.cursor()

    enterprise_name = input()
    mycursor.execute("SELECT n_fabricant FROM listedatabase.entreprises_inspecteurs", (enterprise_name,))
    data = mycursor.fetchall()
    if data:
        code goes there
    else: 
        print('data not found in database')
谢谢你的帮助

我试过了,但没有成功:

import mysql.connector

mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM listedatabase.entreprises_inspecteurs")

for row in mycursor.fetchall():
    print (row[1])

mydb.close()

enterprise_name = input()
 mydb = mysql.connector.connect(host="localhost", user="nn", passwd="passpass")

    mycursor = mydb.cursor()

    enterprise_name = input()
    mycursor.execute("SELECT n_fabricant FROM listedatabase.entreprises_inspecteurs", (enterprise_name,))
    data = mycursor.fetchall()
    if data:
        code goes there
    else: 
        print('data not found in database')

那么
enterprise\u name
去哪里了?比如
选择。。。其中name=?
?@SwetankPoddar链接到谷歌日历api。企业名称由事件的
SUMMARY
描述表示。@tadman是的,它在python代码中的工作方式类似吗?您需要添加
WHERE
子句,不能只附加数据。