Query MySQL database

    0

    50

    databasemysql
    Python public recipes

    sample of query for MySQL

    Shortcut: mysql.query.select

    # db = mysql.connector.connect()
    result = []
    cursor = db.cursor()
    cursor.execute("SELECT field FROM table")
    for x in cursor.fetchall():
      result.append({"field": x[0]})
    cursor.close()
    return result 
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.