Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!c:/Python34/python.exe -u
  2. import mysql.connector
  3. from mysql.connector import (connection)
  4. from mysql.connector import errorcode
  5.  
  6. cnx = connection.MySQLConnection(user='root', password='nika1606',host='127.0.0.1',database='test2')
  7.  
  8. cursor = cnx.cursor()  
  9.  
  10. show_persons= ("Select * from persons")
  11. cursor.execute(show_persons)
  12.  
  13. print("""<!DOCTYPE HTML>
  14.        <html>
  15.        <head>
  16.            <meta http-equiv="content-type" content="text/html charset="utf-8">
  17.            <title>MySQL Table from Python</title>
  18.        </head>\r\n\r\n
  19.        <body>
  20.            <table border="1">""")
  21.  
  22. for (id,name) in cursor:
  23.     print("""<tr><td>{},{}</td></tr>""".format(id,name))
  24.  
  25. print("""</table>
  26.        </body>
  27.        </html>""")
  28.  
  29.  
  30.  
  31. cnx.commit()
  32.  
  33. cursor.close()  
  34. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement