CBSE Class 12 Computer Science
Question 21 of 47
Interface Python with SQL — Question 11
Back to all questions 11
Question 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")- con.connected()
- con.isconnected()
- con.is_connected()
- con.is_connect()
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".