Advertisement
DrAungWinHtut

db.py

Jan 23rd, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. from myconnection import connect_to_mysql
  2.  
  3. config = {
  4.     "host": "127.0.0.1",
  5.     "user": "root",
  6.     "password": "",
  7.     "database": "examdb",
  8. }
  9.  
  10. uname = input("enter username: ")
  11. pwd = input("enter password: ")
  12.  
  13. cnx = connect_to_mysql(config, attempts=3)
  14. if cnx and cnx.is_connected():
  15.     # sql = "SELECT * FROM users where username=%s and password=%s "
  16.     sql = "INSERT INTO users (username,password) values (%s,%s)"
  17.     with cnx.cursor() as cursor:
  18.         result = cursor.execute(sql, (uname, pwd))
  19.         # rows = cursor.fetchall()  # cnx.commit()
  20.         # for row in rows:
  21.         # print(row)
  22.         cnx.commit()
  23.     cnx.close()
  24.  
  25. else:
  26.     print("Could not connect")
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement