Total Complexity | 4 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import mysql.connector |
||
2 | import config |
||
3 | |||
4 | |||
5 | def test_connect(): |
||
6 | cursor = None |
||
7 | cnx = None |
||
8 | try: |
||
9 | cnx = mysql.connector.connect(**config.myems_user_db) |
||
10 | cursor = cnx.cursor() |
||
11 | |||
12 | query = (" SELECT id, name, display_name, email " |
||
13 | " FROM tbl_users " |
||
14 | " ORDER BY id ") |
||
15 | cursor.execute(query) |
||
16 | rows = cursor.fetchall() |
||
17 | print("The config of database is right:", rows) |
||
18 | except Exception as e: |
||
19 | print("The config of database is wrong:", str(e)) |
||
20 | finally: |
||
21 | if cursor: |
||
22 | cursor.close() |
||
23 | if cnx: |
||
24 | cnx.disconnect() |
||
25 | |||
26 | |||
27 | if __name__ == "__main__": |
||
28 | test_connect() |
||
29 |