-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.py
More file actions
38 lines (28 loc) · 926 Bytes
/
connection.py
File metadata and controls
38 lines (28 loc) · 926 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
#sqlite connection
import sqlite3
connection = sqlite3.connect('database.db')
print("Opened database successfully")
conn = connection.cursor()
conn.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL,
password TEXT NOT NULL
);''')
print("Table created successfully")
conn.execute('''
INSERT INTO users (name, email, password)
VALUES ('John Doe', 'bqN2j@example.com', 'password123'),
('GGPw', '4Vq0O@example.com', 'password456');
''')
print("Record inserted successfully")
conn.execute('''
SELECT * FROM users;
''')
print("Record selected successfully")
results = conn.fetchall()
for row in results:
print(row)
conn.close()
connection.close()