-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCh3_2.py
22 lines (20 loc) · 812 Bytes
/
Ch3_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='scraper1',
password='password',
db='DB',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('[email protected]', 'password'))
connection.commit()
with connection.cursor() as cursor:
sql = "SELECT `id`, `password` FROM `users` WHERE `email` = %s"
cursor.execute(sql, ('[email protected]',))
result = cursor.fetchone()
print(result)
finally:
connection.close()