Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql.cursors
- #Here we connect to the database
- connection = pymysql.connect(host='mysql.cc.puv.fi',
- user='e1301181',
- password='4cuJnkhwmRPE',
- db='e1301181_Python',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- #Insert
- try:
- with connection.cursor() as cursor:
- # Here we create a new record
- name = input("Give a name of the customer:\n")
- address = input("Give an address for the customer '"+name+"'\n")
- phone = input("Give a phone number for the customer '"+name+"'\n")
- sql = "INSERT INTO CUSTOMER (address, name, phone) VALUES ('{address}', '{name}', '{phone}')".format(address=address, name=name, phone=phone)
- cursor.execute(sql)
- # Changes are not autocommit by default. So we must commit to save
- # changes.
- connection.commit()
- with connection.cursor() as cursor:
- #Here we make a query
- sql = "SELECT address, name, phone FROM CUSTOMER WHERE name=%s"
- cursor.execute(sql, (name))
- #result = cursor.fetchone()
- result = cursor.fetchall()
- print(result)
- except Exception as e:
- print("Error: " + str(e))
- #update
- #delete
- #dispall
- #dispemp
- finally:
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement