Insert image in Field blob mysql python 2.7

0

I want to insert an image in a blob field of a mysql database with python 2.7 (MySQLdb) but it does not work, it does not show any specific error, it just does not insert the value, the table and the product exist, my code is as follows :

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
import os

photo = open ('10012.jpg','rb')
code = 10012
args =(photo,code)


# Establecemos la conexión con la base de datos
bd = MySQLdb.connect("localhost","root","123","just",port=3306)

# Preparamos el query SQL para obtener el inventario de la base de datos
cursor = bd.cursor()

# Preparamos el query SQL para obtener el inventario de la base de datos
query2 = (" update products set image='?' where code=?;",args)


try:
    # Ejecutamos el comando
   cursor.execute(query2)
   bd.commit()

except:
   print "Error: No se pudo actualizar"
   bd.rollback()

finally:
    bd.close()
    
asked by Ricardo Ulises Prado Uribe 16.08.2018 в 00:29
source

0 answers