Save an image to a Mysql database using Python

Asked

Viewed 594 times

3

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

 foto =cv2.imread('imagem.jpg')
 hora = str(hora.day) + '/' + 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))

1 answer

1


Try this, if it doesn’t work let me know that I edit the answer! Here it worked.

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

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

  • It worked, but how do I save it in jpeg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.