SHARE
TWEET

Untitled

a guest Sep 11th, 2019 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import mysql.connector
  2.  
  3. class DB_conn:
  4.     def __init__(self, host, user, password, database):
  5.         self.mydb = mysql.connector.connect(
  6.             host="127.0.0.1",
  7.             user="basart",
  8.             passwd="megusta",
  9.             database="socialNetwork"
  10.         )
  11.         self.cursor = self.mydb.cursor()
  12.         self.host = host
  13.         self.user = user
  14.         self.password = password
  15.         self.dbname = database
  16.  
  17.     def get_conn(self):
  18.         if self.mydb:
  19.             print('Connected succesfull')
  20.         return self.mydb
  21.  
  22.     def select_curs(self, sql):
  23.         self.cursor.execute(sql)
  24.         for x in self.cursor:
  25.             print(x)
  26.         return x
  27.  
  28.     def insert_curs(self, sql, val):
  29.         self.cursor.execute(sql,val)
  30.         self.mydb.commit()
  31.         self.mydb.rollback()
  32.        
  33. connect = DB_conn("127.0.0.1", "basart", "megusta", "socialNetwork")
  34. connect.get_conn()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top