我有一张用来插入图像的表格。从中,我只需使用MySQL数据库和python3代码检索图像。我的代码执行得很好,但我的问题是每当我检索图像时,它都会显示放在表中的第一个图像,我不知道如何使用for循环逐个检索blob。在
这是我的代码:- 代码.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()
我试过了,但是我没能得到预期的结果。谁能帮我。。。在
我已经试过了,我刚刚得到了预期的产量。。在
相关问题 更多 >
编程相关推荐