Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector as sql
- class Database_Actions:
- def __init__(self):
- db = sql.connect(
- host='localhost',
- user='root',
- passwd='password'
- )
- cursor = db.cursor()
- self.execute_action(db, cursor)
- def execute_action(self, db, cursor):
- while (sql_query := input('Enter SQL > ')) != 'exit':
- try:
- cursor.execute(sql_query)
- for row in cursor.fetchall():
- print(', '.join(str(i) for i in row))
- except Exception as e:
- print(e)
- break
- else:
- print('Work with the database is complete')
- db.close()
- if __name__ == '__main__':
- Database_Actions()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement