import pymysql
f = open('C:\\Users\Allen\Desktop\html style.txt', 'rb')
array = []
for i in f.readlines():
array.append(i.decode('utf8'))
str1 = ''.join(str(x) for x in array)
conn = pymysql.connect(user='root', host='localhost', password='cwl19940125', database='news', charset='utf8')
mycursor = conn.cursor()
sql_insert = 'INSERT INTO test(content) VALUES ("%s");' % str1
mycursor.execute(sql_insert)
conn.commit()
mycursor.close()
conn.close()
錯誤pymysql.err.ProgrammingError:誰能幫助我
pymysql.err.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'"\ufeff\t<section class="_135editor" data-tools="135編輯器" data-id="85433" style\' at line 1')
i print(sql_insert) to let you see it clear
INSERT INTO test(content) VALUES "<section class="_135editor" data-tools="135編輯器" data-id="85433" style="position: relative;">
<section class="135brush" data-style="color: inherit; box-sizing: border-box;line-height: 2em; text-align: center;" style="color: inherit; border-color: rgb(216, 40, 33); box-sizing: border-box; padding: 0px; margin: 0px;">
</section>
</section>";
i add the str and i can't find where syntax is . so i need your help ,can someone to help me?
可能您在單引號或雙引號中遇到了'sql_insert'問題。如果可能的話'print(sql_insert)'並添加結果。 – marmeladze
我只是添加結果 – cwl
@ marmeladze我現在添加它 – cwl