gpt4 book ai didi

mysql - pymysql.err.ProgrammingError : can anyone help me 错误

转载 作者:行者123 更新时间:2023-11-30 22:01:16 26 4
gpt4 key购买 nike

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: (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 = 'INSERT INTO test(content) VALUES ("%s");' % str1

sql_insert = 'INSERT INTO test(content) VALUES ('%s');' % str1
^^ ^^

注意这里的单引号。

>>> qry = """insert into posts(title, body) values('lorem ipsum', '%s')""" %sql
>>> print(qry)
insert into posts(title, body) values('lorem ipsum', '<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;">

关于mysql - pymysql.err.ProgrammingError : can anyone help me 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43255973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com