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")
- con.connected()
- con.isconnected()
- con.is_connected()
- 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
The command used for modifying the records is:
- update()
- add()
- updateall()
- none of these
Which command is used for cleaning up the environment?
- my.closed()
- is.end()
- con.quit()
- mycon.close()
Identify the correct statement to create cursor:
import mysql.connector as msq con = msq.connect() #ConnectionString mycursor = ...............- con.cursor()
- con.create_cursor()
- con.open_cursor()
- con.get_cursor()
Explain the following 'results' retrieval methods with examples.
(a) fetchone()
(b) rowcount
(c) fetchall()