You can download this code by clicking the button below.
This code is now available for download.
This function queries the current logged-in username from the MySQL database.
Technology Stack : MySQL database, mysql-connector-python
Code Type : Database query
Code Difficulty : Intermediate
def fetch_random_user_name(connection):
cursor = connection.cursor(dictionary=True)
cursor.execute("SELECT user() AS username")
result = cursor.fetchone()
cursor.close()
return result['username']