Files
courses/py3interm/EXAMPLES/db_mysql_dictionary_cursors.py
T
2025-05-20 11:57:43 -04:00

30 lines
523 B
Python

#!/usr/bin/env python
import pymysql
import pymysql.cursors
myconn = pymysql.connect(
host="localhost",
db="presidents",
user="scripts",
passwd="scripts",
cursorclass=pymysql.cursors.DictCursor
)
# c = myconn.cursor(pymysql.cursors.DictCursor)
c = myconn.cursor()
# select first name, last name from all presidents
num_recs = c.execute('''
select lastname, firstname
from presidents
''')
print(c.description)
for row in c.fetchall():
print(row['firstname'], row['lastname'])
print()