with open('face.jpg','rb') as f:
img_data=f.read()
find_binary=pymysql.Binary(img_data)
print(find_binary)
add_row="""INSERT INTO IMGS(ID,IMG,编号,DATAIMG) VALUES(7,'K1','NO.','%s')""" % (find_binary)
cursor.execute(add_row)下面是报错原因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 '\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x01\\x01\\x01\\x00H\\x00H\\x00\\x00\\xff\\xdb\\x00C\\x00\\' at line 1")好像是语法原因或者pymysql.binary输出的根本就不是二进制文件,但是不太清楚哪里错了,另外DATAIMG类型是mediumblob
1 回答
小唯快跑啊
TA贡献1863条经验 获得超2个赞
SQL 操作用字符串拼接不是一个好的习惯, 试试用参数化查询:
find_binary=pymysql.Binary(img_data) add_row = """INSERT INTO IMGS(ID,IMG,编号,DATAIMG) VALUES($s, %s, %s, %s)"""cursor.execute(add_row, (7, 'K1', 'NO.', find_binary))
添加回答
举报
0/150
提交
取消