When trying to insert a blob file into a MySQL database, I get errors. This is sample of my code:
@pyqtSlot()
def on_click(self):
file_name = QFileDialog.getOpenFileName(self, 'Open File', 'c:\\', 'Image Files (*.png *.jpg *gif)')
image_path = file_name[0]
self.converttobinary(image_path)
def converttobinary(self, filename):
with open(filename, 'rb') as file:
binarydata = file.read()
mycursor.execute("INSERT INTO imagestore (imgg) VALUES(%s)" % (binarydata))
mydb.commit()
print("image file inserted succesfully")
However, when I run the code I keep getting:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\xd9\x00\x00\x01\x11\x08\x06\x00' at line 1