Advertisement
Guest User

Untitled

a guest
Sep 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import mysql.connector
  2. import time
  3.  
  4. class MyDataBase():
  5.     def __init__(self):
  6.         self.mydb = mysql.connector.connect(
  7.             host="localhost",
  8.             user="root",
  9.             passwd="",
  10.             database="python",
  11.             autocommit=True)
  12.         self.mycursor = self.mydb.cursor()
  13.         self.sql = ""
  14.         self.val = ""
  15.  
  16.     def GetData(self):
  17.         try:
  18.             self.sql = "SELECT id, lastname, firstname, email FROM python"
  19.             self.mycursor.execute(self.sql)
  20.             myresult = self.mycursor.fetchall()
  21.  
  22.             for row in myresult:
  23.                 print(row)
  24.         except:
  25.             print("Error")
  26.  
  27. email = MyDataBase()
  28. print("Querying Database...")
  29. email.GetData()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement