Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/python
  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. add_persons = ("INSERT INTO persons "
  11. "(id,name) "
  12. "VALUES (%s, %s)")
  13.  
  14. show_persons= ("Select * from persons")
  15. cursor.execute(show_persons)
  16. for (id,name) in cursor:
  17. print("""<!DOCTYPE HTML>
  18. <html>
  19. <head>
  20. <meta http-equiv="content-type" content="text/html charset="utf-8">
  21. <title>MySQL Table from Python</title>
  22. </head>
  23. <body>
  24. <table border="1">
  25. <tr><td>"{},{}".format(id,name)</td></tr>
  26. </table>
  27. </body>""")
  28.  
  29. data_persons=(10,'Lisa')
  30. cursor.execute(add_persons,data_persons)
  31. cnx.commit()
  32.  
  33. cursor.close()
  34. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement