update images inside a mysql database

J

Jonas Meurer

hello,

i develop a project with a mysql interface. one mysql table holds all
the images for my project.

everything works quite well so far, except i'm not able to upload images
into the database. the following function does the mysql UPDATE, it
requires the image and the image ID as arguments.

additionally it dumps the image to my filesystem ('/tmp/image.gif') -
i test this with gif images.

for some reason, the file dumped to /tmp/image.gif is exactly the same
as uploaded, but in mysql the file is corrupted, far to small and not
even viewable.

here is my function:

def i_update(image, imgid):
image = "%s" % (image)
sql_exec = """UPDATE Images SET Image='%s' WHERE ImgID = '%s'
""" % (image, imgid)
o = open("/tmp/file.jpg", "w")
o.write(image)
o.close()
db_connect.cursor.execute(sql_exec)


i've the strong feeling that the substitution makes problems. if the
string 'image' conains ' or " for example, the sql_exec is broken.

what do you suggest?

bye
jonas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top