Luticus

start of mariadb class in python

May 21st, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import pymysql as mariadb
  2.  
  3.  
  4. class MariaDB():
  5.     """
  6.    connects to database  and sends/recieves sql statements
  7.    """
  8.  
  9.     __connection = ""
  10.     __cursor = ""
  11.     __connected = False
  12.  
  13.     def __init__(
  14.             self,
  15.             database,
  16.             user,
  17.             password,
  18.             host="localhost",
  19.             port=3306,
  20.     ):
  21.         """
  22.        [constructor]
  23.        Connect to database
  24.  
  25.        database [string] database you want to connect to
  26.  
  27.        user [string] username
  28.  
  29.        password [string] password
  30.  
  31.        host [string] remote system to connect to
  32.                      (default: localhost)
  33.  
  34.        port [int] port number to connect to
  35.                   (default: 3306)
  36.        """
  37.         try:
  38.             self.__connection = mariadb.connect(
  39.                 host=host,
  40.                 user=user,
  41.                 password=password,
  42.                 database=database,
  43.             )
  44.             self.__cursor = self.__connection.cursor()
  45.             self.__connected = True
  46.         except Exception as exception:
  47.             print(exception)
  48.             quit()
Add Comment
Please, Sign In to add comment