-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.py
84 lines (49 loc) · 1.73 KB
/
users.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Intergrating MySQL database with Python
# Module: pymsql
import pymysql
# Create a database connection
# Use the function Connect with the parameters
# Connect(host='', user = '' ,password = ''(if access requires a password), database = '')
connection = pymysql.connect(host='localhost', user='root', password='Kifaru12345', database='MpesaTestDB')
print("Database connected successfully")
# 2. Inserting Data to the Tables
username = "Brownnie254"
password = '123456'
phone = '0702480881'
# Cursors : A cursor is a propert(State) used to execute sql codes on python
# Prepared statements (%s):They indicate that values will be passed during sql execution
cursor = connection.cursor()
sql = "insert into user (username, password, phone) values (%s, %s, %s)"
# 3. sql execution:
data = (username, password, phone)
cursor.execute(sql, data)
# Commit
username = "Toma Tech"
password = '000000'
phone = '0732584589'
cursor = connection.cursor()
sql = "insert into user (username, password, phone) values (%s, %s, %s)"
data = (username, password, phone)
cursor.execute(sql, data)
connection.commit()
username = "Andrew Tate"
password = 'qwerty123'
phone = '0774859632'
cursor = connection.cursor()
sql = "insert into user (username, password, phone) values (%s, %s, %s)"
data = (username, password, phone)
cursor.execute(sql, data)
connection.commit()
username = "Edh Malik"
password = '789456123'
phone = '0775489623'
cursor = connection.cursor()
sql = "insert into user (username, password, phone) values (%s, %s, %s)"
data = (username, password, phone)
cursor.execute(sql, data)
connection.commit()
print("Record Saved Successfully")
#SELECTS : Log In, Ecommerce.......
#UPDATE
#DELETE
#FLASK : python framework to run web application