Skip to content

Instantly share code, notes, and snippets.

@stefanmonkey
Created January 8, 2014 08:13
Show Gist options
  • Save stefanmonkey/8313445 to your computer and use it in GitHub Desktop.
Save stefanmonkey/8313445 to your computer and use it in GitHub Desktop.
insert image
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
def read_image():
fin = open("woman.jpg")
img = fin.read()
return img
con = mdb.connect('localhost', 'testuser', '123456', 'testdb')
with con:
cur = con.cursor()
data = read_image()
cur.execute("INSERT INTO images VALUES(1, %s)", (data, ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment