Я создал базу данных с MySQLdb.
В базе данных у меня есть таблица с именем student
со столбцами:
id(is int),
id_user(is int),
f_name(is str),
l_name(is str)
Я хочу обновить строку.
Мой код ниже:
db=mdb.connect(host="localhost", use_unicode="True", charset="utf8",
user="", passwd="", db="test")
# prepare a cursor object using cursor() method
cursor = db.cursor()
sql="""SELECT id_user FROM student"""
try:
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
except:
# Rollback in case there is any error
db.rollback()
rows = cursor.fetchall()
the=int(7)
se=str('ok')
for row in rows:
r=int(row[0])
if r==the:
sql2 = """UPDATE student
SET f_name=%s
WHERE id_user = %s"""% (se,the)
# Execute the SQL command
cursor.execute(sql2)
# Commit your changes in the database
db.commit()
db.rollback()
# disconnect from server
db.close()
Когда я запускаю его, я получаю сообщение об ошибке: есть столбец с именем ok, почему?
Может кто-нибудь помочь мне найти, что я делаю не так, пожалуйста?