Pymysql Query Executor Function

  • Share this:

Code introduction


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                
              
Tags: