简体   繁体   中英

Executing MySQL Queries in Python not work properly

I have problem with queries in python script.

In phpmyadmin the same queries works properly, but in script, second query not work. (No errors, no Insert)

my code:

from sys import argv
import MySQLdb
################
#
# python dbinsert.py "radiostion" "track" "url"
#
###############
db = MySQLdb.connect(host="localhost",
                    user="root",
                    passwd="xxxxxx",
                    db="cjgb")
cur = db.cursor()
cur.execute("""SELECT MAX( Date ), Name
            FROM Track
            WHERE Station = %s""", argv[1])
name = ""
for row in cur.fetchall():
    name = row[0]
if nazwa is not argv[2]:
    cur.execute("""
                INSERT INTO Track VALUES
                ("%s", SYSDATE(), "%s", "%s", "%s", "%s")
                """,
                (argv[1], argv[2], argv[2], argv[2], argv[3]))

What is wrong? Thanks for answers.

您需要在插入后运行db.commit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM