简体   繁体   English

如何通过使用python按下按钮将数据输入数据库?

[英]How can I enter data into database by pressing the button with using python?

我正在使用 python 语言设置一个项目,通过按下按钮从客户那里获取反馈,我的问题是关于将数据输入数据库的代码?

import mysql.connector
connector = mysql.connector.connect(host="host", user="user", passwd="password", database="DB")
cnx = connector.cursor()
cnx.execute("INSERT INTO ... VALUES (%s)", ('data'))
# Or execute a query just as always
#cnx.execute("INSERT INTO ... VALUES (...)")
connector.commit()
# If "SELECT * FROM ..." use next line to get the data
#result = cnx.fetchall()
cnx.close()
connector.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何绑定在python中按下按钮并按下Enter键? - How can I bind pressing a button and hitting an enter key in python? 如何在python 2.7中按下按钮“输入”,而无需用户按下它,从代码 - How can I press the button "enter" in python 2.7, without having the user pressing it, from code 如何使用Flask,postgres和Python上传一个csv文件并将数据输入数据库? - how can I upload a csv file and enter the data into a database, using Flask, postgres and Python? 按 Enter 时如何终止循环 - How can I terminate a loop when pressing Enter 如何在按Enter的同时循环文本(Python) - How to loop a text whilst pressing enter (Python) 如何在 Python 中模拟按键按下“ENTER”? - How to simulate the key's pressing 'ENTER' in Python? 如何将输入输入框 (tkinter) 的文本分配给 python 脚本中的变量并通过按下按钮运行脚本? - How can I assign the text imputed into an entry box (tkinter) to variable in python script and run the script by pressing a button? 在前端按下按钮后,如何在 web 服务器(nodeJS)中运行 python 脚本? - How can I run a python script in a web server (nodeJS) after pressing a button on frontend? 在 Python Tkinter 中按下按钮后如何清除窗口? - How do i clear a window after pressing a button in Python Tkinter? 如何通过按下按钮更新标签文本 - How can i update label text by pressing button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM