31 lines
725 B
Python
Raw Normal View History

2025-04-27 16:36:34 +08:00
import pymysql
2025-04-27 12:04:10 +08:00
class Tool:
id = 0
name = ""
typeid = 0
2025-04-27 16:36:34 +08:00
def __init__(self, id, typeid):
2025-04-27 12:04:10 +08:00
self.id = id
self.typeid = typeid
2025-04-27 16:36:34 +08:00
def get_tool_name(id):
2025-04-27 16:36:34 +08:00
conn=pymysql.connect(host = '192.168.31.9' # 连接名称,默认
,user = 'saipo'
,passwd='Grasste0403' # 密码
,port= 3306 # 端口默认为3306
,db='saipo' # 数据库名称
,charset='utf8' # 字符编码
)
cur = conn.cursor()
sql = "SELECT name FROM tool WHERE id = %s"
cur.execute(sql, (id,))
result = cur.fetchone()
cur.close()
conn.close()
if result:
return result[0]
else:
return None