Guest User

Untitled

a guest
Feb 15th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class DBExecutor(): def init(self, connection_params): self._connection_params = connection_params self._connection = None def _connect(self): self._connection = pymysql.connect(self._connection_params) def execute(self, sql, *args, kwargs): if not (self._connection and self._connection.ping(True)): self._connect(): with self._connection.cursor() as cursor: cursor.execute(sql, *args, kwargs) self._connection.commit() # использование db_executor = DBExecutor(host='127.0.0.1', user='root', password='', db='python', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor, autocommit=True) db_executor.execute("INSERT INTO scaner (number) VALUES (%s)", ('text',))
Add Comment
Please, Sign In to add comment