HOME/Articles/

mysql example findall (snippet)

Article Outline

Python mysql example 'findall'

Functions in program:

  • def findAll():

python findall

Python mysql example: findall

def findAll():
    import mysql.connector

    connect = mysql.connector.connect(
        user="username",
        password="password",
        database="database",
        charset="utf8",
        buffered=True)

    cursor = connect.cursor()

    sql="SELECT * FROM table"
    cursor.execute(sql)
    row = cursor.fetchone()
    while row is not None:
        yield row
        row = cursor.fetchone()