import MySQLdb from config import config def simple_mysql( environ, start_response ): # # collegamento al mysql # # for more options see: # http://mysql-python.sourceforge.net/MySQLdb.html#introduction conn = MySQLdb.connect( host = config['MYSQL_HOST'], user = config['MYSQL_USER'], passwd = config['MYSQL_PASSWORD'], db = config['MYSQL_DB'] ) # # esecuzione query # cur = conn.cursor( MySQLdb.cursors.DictCursor ) cur.execute( 'SHOW tables;' ) # # recupero record e generazione html # start_response( '200 OK', [('Content-Type', 'text/plain')] ) for record in cur.fetchall(): yield "\n" + str( record ) # # chiusura connessione al mysql # conn.close()