I have one table for inserting images. From that, I just retrieve images using MySQL database and Python 3 code. My code is executed well, but my problem is whenever I retrieve images it is showing me first image which is placed in my table and I don't know how can I retrieve blobs one by one using for loop.
Here is my code:- code.py:
from PIL import Image
import pymysql
from api import mysql
db=pymysql.connect(host="localhost",user="root",passwd="root",db="votelist")
image = Image.open('D:/mine project/face_reg/media/a.jpg')
blob = open('D:/mine project/face_reg/media/a.jpg', 'rb').read()
sql = 'INSERT INTO imo(image) VALUES(%s)'
args = (blob)
cursor=db.cursor()
cursor.execute(sql,args)
sql1='select image from imo'
# i=sql1
# for image in i:
# print(i)
# else:
# print("no")
db.commit()
cursor.execute(sql1)
data=cursor.fetchall()
print ('Inserted')
file_like=io.BytesIO(data[0][0])
img=PIL.Image.open(file_like)
img.show()
print('retrieved')
db.close()
I have tried, but I can't get my expected output..Can anyone help me...
args = (blob)is missing a comma. It should beargs = (blob,)in order to make it a 1-tuple.