Hello!
Python not so long ago studied, there is a question...
Is it possible to create a DB connection (MySQL) in all Python files Telegram Bot? (In this case, three files)
Currently struggling with this:
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
Struggling like so:
# 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', ... the connection.
And so in three files.
Thanks for any help, hint!
check_and_select_something() here to stream all your samples from the base? - Jose_Cole73 commented on April 19th 20 at 12:12
I guess I confused You.... Starting from the initial question, You can create a connection to the database multiple times in Your file; but I have suggested to keep the variable with the connection somewhere in one file and whenever it is used to perform the connection.ping() at the time of the execution of the required queries (that is, instead of the
cursor.execute('SELECT *')
in the example above You describe your query:cursor.execute("Your SQL query")
) to handle exceptions. - Hellen_Leuschke6 commented on April 19th 20 at 12:15Can see how it will save!? Please! :)
Plug-in
Use
- Jose_Cole73 commented on April 19th 20 at 12:18