Instance Eight: read image files from database

#!/usr/bin/env python
#--*-- coding:utf-8 --*--
__author__ = 'Kevin'

import MySQLdb as mdb
import sys

try:
    conn = mdb.connect('localhost','root','redhat','test')
    cursor = conn.cursor()

    cursor.execute("SELECT Data FROM Images LIMIT 1")

    fout = open('image.png','wb')
    fout.write(cursor.fetchone()[0])

    fout.close()
    cursor.close()
    conn.close()
except IOError,e:
    print "Error %d:%s" % (e.args[0],e.args[1])
    sys.exit(1)

 Result:python

    從你的項目文件夾中能找到該IMAGEfetch

相關文章
相關標籤/搜索