Python public recipes
Query two colums from a MySQL table and return the result as an array. Each value in the array is a dictionary with the column name as a key.
Library: mysql-connector-python
# db is a connection to MySQL created with mysql.connector.connect()
cursor = db.cursor()
# Make sure we schedule only active projects
cursor.execute("SELECT col1, col2 FROM table")
for x in cursor.fetchall():
result.append({"col1": x[0], "col2": x[1]})
cursor.close()