AttributeError: 'SQLAlchemy' object has no attribute 'connection'.How to connect sqlalchemy to mysql?

Viewed 193
if request.method == 'POST' and 'username' in request.form and 'password' in request.form:
    # Create variables for easy access
    username = request.form['username']
    password = request.form['password']
    # Check if account exists using MySQL
    
    
    cursor = db.connection.cursor(db.cursors.DictCursor)
    cursor.execute('SELECT * FROM accounts WHERE username = %s AND password = %s', (username, password,))
    # Fetch one record and return result
    account = cursor.fetchone()

Error:

cursor = db.connection.cursor(db.cursors.DictCursor) AttributeError:
'SQLAlchemy' object has no attribute 'connection'

0 Answers
Related