Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql.cursors
- # Connect to the database
- connection = pymysql.connect(host='localhost',
- user='root',
- #password='passwd',
- db='db',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- cursor = connection.cursor()
- # SELECT statement
- sql = "SELECT * FROM table;"
- cursor.execute(sql)
- result = cursor.fetchone() # Results are returned as a dictionary
- print(result)
- # INSERT statement
- sql = "INSERT INTO table ('email', 'password') VALUES (%s, %s)"
- cursor.execute(sql, ('test@example.com', 'password'))
- # Statements that change the content
- # of a table MUST be committed!
- connection.commit()
- # Close connection
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement