Skip navigation links

User Comments

Posted by Will Lowrey on April 10 2013 6:52pm[Delete] [Edit]

It would be worthwhile to show a single argument within the query. When I tried to initially use this, and I provided a string argument, I received a ProgrammerError because of the number of arguments provided. It wasn't clear that the string I was passing in was being converted into a tuple of each character.

import mysql.connector
config = { 'user': 'db_username',
'password': 'yourpasswordhere',
'host': 'localhost',
'port': 3306,
'database': 'yourdbnamehere',
}

cnx = mysql.connector.connect(**config)

def get_user_by_email(email):

query = ("SELECT * FROM user_list WHERE email_address = %s")
args = (email,)

cursor = cnx.cursor()
cursor.execute(query, args)
results = cursor.fetchall()
print(results)
cursor.close()

def main():
get_user_by_email('bob@example.com')
cnx.close()





Add your own comment.