Home > Database > Mysql Tutorial > python把变量如何写入mysql

python把变量如何写入mysql

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 09:40:31
Original
1285 people have browsed it

mysqlsqlpython数据库

GAME_ID = s["resultSets"][0]["rowSet"][i][0]

TEAM_ID = s["resultSets"][0]["rowSet"][i][1]
PLAYER_NAME = s["resultSets"][0]["rowSet"][i][5]

db = MySQLdb.connect("localhost","root","199536abc","test")

cursor = db.cursor()
sql = """INSERT INTO PLAYER(GAME_ID,TEAM_ID,NAME)
VALUES (GAME_ID,TEAM_ID,PLAYER_NAME)"""

try:
# 执行sql语句
cursor.execute(sql)
# 提交到数据库执行
db.commit()
except:
# Rollback in case there is any error
db.rollback()

<code>                现在的问题是sql语句里values后面括号里的三个不是之前定义的GAME_ID,TEAM_ID,PLAYER_NAME,                只能写固定值“21212”,1212,“nick”这样的                求解</code>
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template