#! /usr/bin/python import cgi import cgitb import sys import MySQLdb def returnError(errorString): print """

%s

"""%errorString cgitb.enable() print "Content-type: text/xml" print "" print '' # Get the form data form = cgi.FieldStorage() if not (form.has_key("sql")): returnError("No SQL string?") sys.exit(0) sqlStatement = form["sql"].value rows = None try: conn = MySQLdb.connect (host="127.0.0.1", db="bmi219") cursor = conn.cursor() cursor.execute(sqlStatement) rows = cursor.fetchall() cursor.close() conn.commit() conn.close() except MySQLdb.Error, e: returnError(e.args[1]) sys.exit(0) print '' print '' print '' print '', for column in cursor.description: print '', print '' for row in rows: print '', for cell in row: print '', print '' print '
'+column[0]+'
'+str(cell)+'
' print '' print ''