You can download this code by clicking the button below.
This code is now available for download.
This function accepts a database connection object and an SQL query string as arguments, executes the query, and returns the results.
Technology Stack : pymysql
Code Type : Database Query Execution
Code Difficulty : Intermediate
def execute_query_with_pymysql(connection, query):
cursor = connection.cursor()
cursor.execute(query)
results = cursor.fetchall()
cursor.close()
return results