25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
794 B

  1. import MySQLdb
  2. from config import config
  3. def simple_mysql( environ, start_response ):
  4. #
  5. # collegamento al mysql
  6. #
  7. # for more options see:
  8. # http://mysql-python.sourceforge.net/MySQLdb.html#introduction
  9. conn = MySQLdb.connect(
  10. host = config['MYSQL_HOST'],
  11. user = config['MYSQL_USER'],
  12. passwd = config['MYSQL_PASSWORD'],
  13. db = config['MYSQL_DB']
  14. )
  15. #
  16. # esecuzione query
  17. #
  18. cur = conn.cursor( MySQLdb.cursors.DictCursor )
  19. cur.execute( 'SHOW tables;' )
  20. #
  21. # recupero record e generazione html
  22. #
  23. start_response( '200 OK', [('Content-Type', 'text/plain')] )
  24. for record in cur.fetchall():
  25. yield "\n" + str( record )
  26. #
  27. # chiusura connessione al mysql
  28. #
  29. conn.close()