-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mysql.py
More file actions
43 lines (28 loc) · 848 Bytes
/
test_mysql.py
File metadata and controls
43 lines (28 loc) · 848 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
41
42
43
import mysql.connector
import datetime
import json
# Configuración
with open(r'C:\TRABAJO\Python\Pythonanywhere\repo_pythonanywhere\pythonanywhere\config.json') as json_file:
config = json.load(json_file)
#config = {
# 'user': 'alggea',
# 'password': 'sito28',
# 'host': '127.0.0.1',
# 'database': 'prueba_db',
# 'raise_on_warnings': True
#}
print(config)
cnx = mysql.connector.connect(**config)
print(cnx)
#query = ("SELECT id, nombre, email FROM tbl_prueba "
# "WHERE hire_date BETWEEN %s AND %s")
#hire_start = datetime.date(1999, 1, 1)
#hire_end = datetime.date(1999, 12, 31)
#cursor.execute(query, (hire_start, hire_end))
cursor = cnx.cursor()
query = ("SELECT id, nombre, email FROM tbl_prueba")
cursor.execute(query)
for (id, nombre, email) in cursor:
print(id, nombre, email)
cursor.close()
cnx.close()