Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import mysql.connector
- from mysql.connector import (connection)
- from mysql.connector import errorcode
- cnx = connection.MySQLConnection(user='root', password='nika1606',host='127.0.0.1',database='test2')
- cursor = cnx.cursor()
- add_persons = ("INSERT INTO persons "
- "(id,name) "
- "VALUES (%s, %s)")
- show_persons= ("Select * from persons")
- cursor.execute(show_persons)
- for (id,name) in cursor:
- print("""<!DOCTYPE HTML>
- <html>
- <head>
- <meta http-equiv="content-type" content="text/html charset="utf-8">
- <title>MySQL Table from Python</title>
- </head>
- <body>
- <table border="1">
- <tr><td>"{},{}".format(id,name)</td></tr>
- </table>
- </body>""")
- data_persons=(10,'Lisa')
- cursor.execute(add_persons,data_persons)
- cnx.commit()
- cursor.close()
- cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement