Saving an image to a MySQL database using Python


I don't know how to save the image in the database.

 foto =cv2.imread('imagem.jpg')
 hora = str( + '/' + str(hora.month) + '/' + str(hora.year) + '-' + str(hora.hour) + ':' + str(hora.minute) + ':' + str(hora.second)
 cursor.execute('SELECT * FROM acesso_usuarios.william')
 cursor.execute('INSERT INTO william (entrada, foto) VALUES (?, ?), (hora, foto))


Try this, if it doesn't work, let me know and I'll edit the answer! Here it worked.

   cursor.execute("INSERT INTO william (entrada, foto) VALUES (%s, %s)", (hora, foto))

If you have questions click here and read a very interesting tutorial.

Scroll to Top