Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import pymysql
  2.  
  3. connection = pymysql.connect(host='localhost', user='root', password='', db='uni', cursorclass=pymysql.cursors.DictCursor)
  4.  
  5.  
  6. def search_database():
  7. with connection.cursor() as cursor:
  8. cursor.execute("SELECT * FROM `student`")
  9. results = cursor.fetchall()
  10. return results
  11.  
  12.  
  13. def add_student(student_name, student_email, course_id):
  14. with connection.cursor() as cursor:
  15. cursor.execute(f'INSERT INTO student (student_name, student_email, courseid) VALUES ("{student_name}","{student_email}",{course_id})')
  16. connection.commit()
  17. print("Done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement