How does python write variables into mysql?

Source: Internet
Author: User
GAME_IDs [& quot; resultSets & quot;] [0] [& quot; rowSet & quot;] [I] [0] TEAM_IDs [& quot; resultSets & quot;] [0] [& quot; rowSet & quot;] [I] [1] PLAYER_NAMEs [& quot; resultSets & quot;] [0] [& quot; rowSet & quot;] [I] [5] dbMySQLdb. connect (& quot; localhost & quot;, & quot; ro mysqlsqlpython database

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:
# Execute SQL statements
Cursor.exe cute (SQL)
# Submit to database for execution
Db. commit ()
Except t:
# Rollback in case there is any error
Db. rollback ()

The problem is that the three values in the brackets following the values in the SQL statement are not the previously defined GAME_ID, TEAM_ID, PLAYER_NAME, and can only be fixed values such as 21212, 1212, and nick.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.