1

下面有什么问题?

import MySQLdb as mysql
import datetime

db = mysql.connect("localhost","root","passworld","employees" )
cursor = db.cursor()

sql = "INSERT INTO employee(id, firstname, surname, sex, employmentdate) VALUES (%s, %s, %s, %s, '%s')" %(id, firstname, surname, sex, employmentdate)

dater = datetime.datetime(2005,1,1)
cursor.execute(["012345","Mark", "Rooney", "M", dater])

OperationalError: (1054, "Unknown column 'Mark' in 'field list'")
4

1 回答 1

1

您应该将您的 sql 语句和参数传递给cursor.execute()

sql = "INSERT INTO employee(id, firstname, surname, sex, employmentdate) VALUES (%s, %s, %s, %s, '%s')"
cursor.execute(sql, ["012345","Mark", "Rooney", "M", dater])
db.commit()
于 2013-09-05T14:05:59.333 回答