Computer Science

Which function of connection is used to check whether connection to MySQL is successfully done or not?

import mysql.connector as mycon
con = mycon.connect               #ConnectionString
if ...............:
    print("Connected!")
else:
    print("Error! Not Connected")
  1. con.connected()
  2. con.isconnected()
  3. con.is_connected()
  4. con.is_connect()

Python MySQL

1 Like

Answer

con.is_connected()

Reason — In the provided code using mysql.connector, the correct function to check whether the connection to MySQL is successfully established or not is con.is_connected(). If the connection is active, it prints "Connected!". Conversely, if the connection is not active, it prints "Error! Not Connected".

Answered By

1 Like


Related Questions