A
A
Artemy Family2020-04-15 14:05:06
Python
Artemy Family, 2020-04-15 14:05:06

Is it possible to create a DB connection in all Python Telegram Bot files?

Hello!

I have been studying Python not so long ago, the question has arisen ...

Is it possible to create a connection to the database (MySQL) in all Python Telegram Bot files? (In this case, in three files)

I'm currently struggling with this:
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query') I'm struggling

like this:

# if the connection was lost, then it reconnects
db.ping(reconnect=True)
db.query('SET GLOBAL connect_timeout=86000')

if db.open is False:
    max_try = 15
    tryt = 0
    while db.open is False:
        if tryt < max_try:
            db.ping() # autoreconnect is true by default
        tryt +=1


db = pymysql.connect(host='localhost', ... connection itself.
And like this in three files.

Thanks for any help, hint!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question