Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- cnx = mysql.connector.connect(user='furby', password='something',host='127.0.0.1', database='mydb')
- cursor = cnx.cursor()
- document_root = ET.fromstring(semester.read('data'))
- semester_name = document_root.get("Name")
- print(semester_name)
- query = ("SELECT semester_id FROM StudentData.semesters where name = '%s'")
- cursor.execute(query % semester_name)
- cursor.fetchall()
- print(cursor.rowcount)
- if (cursor.rowcount == 0):
- print("hi")
- start_date = document_root.get("StartDate")
- end_date = document_root.get("EndDate")
- notes = document_root.get("Notes")
- try:
- cursor.execute("INSERT INTO StudentData.semesters (name, start_date, end_date, notes) VALUES ('" + semester_name + "', '" + start_date + "', '" + end_date + "', '" + notes + "')")
- except:
- print("error")
- print("done")
Add Comment
Please, Sign In to add comment