-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
38 lines (31 loc) · 1.12 KB
/
test.py
File metadata and controls
38 lines (31 loc) · 1.12 KB
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
import pymysql
from mysql.connector import Error
import passwords
class Conn():
def __init__(self):
hostname = passwords.hostname
database = passwords.database
password = passwords.password
port = passwords.port
username = passwords.username
self.connection = pymysql.connect(host=hostname, database=database, user=username, password=password,
port=port)
if self.connection.is_connected():
db_Info = self.connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
self.cursor = self.connection.cursor()
self.cursor.execute("select database();")
record = self.cursor.fetchone()
print("You're connected to database: ", record)
self.connection.commit()
def func(self):
query = """SELECT * FROM config"""
self.cursor.execute(query)
print(self.cursor.fetchall())
self.connection.commit()
def close(self):
self.cursor.close()
self.connection.close()
c = Conn()
c.func()
c.close()