Date: 06/19/05 (Web Development) Keywords: mysql, browser, database, sql Hi everyone this is my first post and my first Python script.
#!/usr/bin/python
import MySQLdb, cgi, string, os
def getScriptname():
""" Return the scriptname part of the URL. """
return os.environ.get('SCRIPT_NAME', '')
def getPathinfo():
""" Return the remainparth of the URL. """
pathinfo = os.environ.get('PATH_INFO' '')
# fix fr a well known bug in IIS/4.0
if os.name == 'nt':
scriptname = getScriptName()
if string.find(pathinfo, scriptname) == 0:
pathinfo = pathinfo[len(scriptname):]
return pathinfo
def getData(idNumber):
Con = MySQLdb.connect(host="",
db="",
port=3306,
user="",
passwd="")
Cursor = Con.cursor()
sql = "SELECT binary_data FROM pictures WHERE picture_id = '15'"
Cursor.execute(sql)
# print sql
# print idNumber
result = Cursor.fetchall()
Con.close()
return result
idNumber = 55
data = getData(idNumber)
print """Content-type: image/jpeg
"""
print data[0]
Source: http://www.livejournal.com/community/webdev/212040.html
|