Feb-08-2022, 06:15 AM
I want to connect to a database in a remote server (namecheap Cpanel)
Os: wisdows 11
Here's my code:
Os: wisdows 11
Here's my code:
def connect_to_db(): # function connect to database return mysql.connector.connect(host='server.web-hosting.com', user="me_tomtom", passwd="*****", database= "db_name", port = 2083 ) def mydb_data(table_name, loop, user_id, index): # function returns a specified index data in db mydp = connect_to_db() my_cursor = mydp.cursor(buffered=True) my_cursor.execute(f"SELECT * FROM {table_name}") for data in my_cursor: print(data) if data[loop] == user_id: return data[index]then I call mydb_data function
print(mydb_data('demo_bot_users',1,'123r24gte3221', 3))Error I'm having:
Error: File "C:\Users\elect\AppData\Local\Programs\Python\Python38\lib\site-packages\mysql\connector\network.py", line 264, in recv_plain
raise errors.InterfaceError(errno=2013)
mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query
PS C:\Project\exe>
Please what is the cause of this error and how can i fix it? Support would be highly appreciated👍