python查询运行,但不插入mysql

mbyulnm0  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(252)

我有一个糟糕的python脚本,它连接到一个db获取信息,然后使用一些变量将这些信息输入到db中。我已经调整了代码,直到它运行没有错误,但最终它没有实际插入到数据库中的任何东西。这是我正在使用的插入代码

company_name = input("what is the company name?: ")
host=("")
ts = time.time()
timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')

# Start DB connection

conn = mysql.connector.connect (user=dbUser,password=dbPassword,host=host,buffered=True)
cursor = conn.cursor()

# Print Database Information

select_db = ("")
cursor.execute(select_db)
api_keys = ("select * from api_keys order by API_KEYS_ID desc limit 1")
cursor.execute(api_keys)

# print(api_keys)

# for (api_keys) in cursor:

# print(api_keys[0])

# api_key_id = api_keys[0] + 1

# print(api_key_id)

api_keys_id = 170

## 

add_api_key = ("INSERT INTO api_keys(api_keys_id, api_key, status, email, ip_address, filter_query, create_date, description) \
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",  (api_keys_id , api_token , 'A' , email , '*' , '(OwnerPartyID:' + ownerPartyID + ') AND (SalesStatus:' + salesStatus + ')' , timestamp , company_name + ' key'));

cursor.execute(*add_api_key)
conn.commit()
print(add_api_key)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题