Reputation: 43
I want to get the data by column name but when I type the column name I get an error.I want to use it like this: user['username'], This is my python code:
mydb = mysql.connector.connect(host=config['MYSQL']['DB_HOST'],
user=config['MYSQL']['DB_USERNAME'], passwd=config['MYSQL']['DB_PASSWORD'], database=config['MYSQL']['DB_DATABASE'])
mycursor = mydb.cursor(buffered=True)
mycursor.execute("select * from users")
users = mycursor.fetchall()
for user in users:
username = user[2]
Upvotes: 0
Views: 35
Reputation: 170
You should use this dictionary=True
mycursor = mydb.cursor(buffered=True, dictionary=True)
Upvotes: 1