Fetching multiple rows from mySQL in Python

37 views Asked by At

I want to fetch multiple rows from mySQL in Python, put in a string on new line each.

mycursor.execute("SELECT ProductName FROM products ;")

    if mycursor.rowcount == 0:
        products = "No Products."
    else:
        products = ""
        for row in mycursor.fetchall():
            products += "{ProductName} ".format(**row)

For the above code, I get below error:

str.format() argument after ** must be a mapping, not tuple

0

There are 0 answers