Gremlin/Gremlin_Python/Gremlin_Python.py

39 lines
1.1 KiB
Python

import mysql.connector as database
connection = database.connect(
host="woitschetzki.de",
port="3306",
user="sascha",
password="mgltoJtmmDnKJ86LltsGdw",
database="regulus")
cursor = connection.cursor()
def getContact(lastName):
try:
statement = "SELECT ContactId, AccountId, FirstName, LastName, Gender, Email FROM Contacts WHERE LastName LIKE %s"
data = (lastName,)
cursor.execute(statement, data)
rows = list(cursor)
print(f"Found {len(rows)} contacts with {lastName} in LastName:")
print("ContactId | AccountID | FirstName | LastName | Gender | Email")
for (contactId, AccountId, firstName, lastName, gender, email) in rows:
print(
f"{contactId} | {AccountId} | {firstName} | {lastName} | {gender} | {email}")
except database.Error as error:
print(f"Error retrieving entry from database: {error}")
print("Willkommen bei Gremlin_Python!")
while 2 > 1:
print("Nach welchem Kunden suchen Sie?: ")
contactSearch = input()
getContact(f"%{contactSearch}%")
connection.close()