Database Connection Function

  • Share this:

Code introduction


This function connects to a specified database and requires the hostname, username, password, and database name.


Technology Stack : PyMySQL

Code Type : Database Connection

Code Difficulty : Intermediate


                
                    
def connect_to_database(host, user, password, db):
    import pymysql
    connection = pymysql.connect(host=host, user=user, password=password, db=db)
    return connection                
              
Tags: