Я создал базу данных с MySQLdb.
В базе данных у меня есть таблица с именем student
с колоннами:Ошибка Mysqldb с установкой% s
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()
Когда я запускаю его я беру ошибку есть столбец с именем ОК, почему?
Может ли кто-нибудь помочь мне найти то, что я делаю неправильно, пожалуйста?
Вы должны вложить строки в одинарные кавычки. –