Guest User

Untitled

a guest
Nov 26th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import mysql.connector
  2.  
  3. cnx = mysql.connector.connect(user='furby', password='something',host='127.0.0.1', database='mydb')
  4. cursor = cnx.cursor()
  5.  
  6. document_root = ET.fromstring(semester.read('data'))
  7. semester_name = document_root.get("Name")
  8. print(semester_name)
  9. query = ("SELECT semester_id FROM StudentData.semesters where name = '%s'")
  10. cursor.execute(query % semester_name)
  11. cursor.fetchall()
  12. print(cursor.rowcount)
  13. if (cursor.rowcount == 0):
  14. print("hi")
  15. start_date = document_root.get("StartDate")
  16. end_date = document_root.get("EndDate")
  17. notes = document_root.get("Notes")
  18. try:
  19. cursor.execute("INSERT INTO StudentData.semesters (name, start_date, end_date, notes) VALUES ('" + semester_name + "', '" + start_date + "', '" + end_date + "', '" + notes + "')")
  20. except:
  21. print("error")
  22.  
  23. print("done")
Add Comment
Please, Sign In to add comment