forked from devopsloft/devopsloft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis_member_exists.py
More file actions
40 lines (28 loc) · 875 Bytes
/
is_member_exists.py
File metadata and controls
40 lines (28 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import mysql.connector
config = {
'user': 'root',
'password': '12345',
'host': 'localhost',
'database': 'devopsloft',
'raise_on_warnings': True
}
def is_email_exists(email):
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
query = "SELECT count(*) AS count_users FROM users WHERE email ='" +\
email + "'"
cursor.execute(query)
query_result = cursor.fetchall()
cursor.close()
cnx.close()
is_exists_email = False
# loop should run once.
for (count_users) in query_result:
is_exists_email = count_users[0] != 0
return is_exists_email
# better way but didn't work
# query = ("SELECT first_name, last_name FROM users "
# "WHERE first_name ='%s'")
# cursor.execute(query, (first_name))
# test functionality
print(is_email_exists('myemail@gmail.com'))