Q. Explain
the following 'results' retrieval methods with examples.
A. fetchone ()
B. rowcount ()
C. fetchall ()
Answer =
(A) fetchone() :- The fetchone() method will return only one row from the result set in the form of tuple containing a record.
(B) rowcount() :- cursor.rowcount() that always return how many records have been retrieved so for using any of the fetch..() methods.
(C) fetchall() :- The fetchall() method return all the rows from the result set in the form of a tuple congaing the records.
For example:-
import mysql.connector as a
mydb = a.connect(host="localhost",user="root",password="portal express", database = " Path_wala ")
cur = mydb.cursor()
run = "select * from Path_wala order by salary "
cur . execute(run)
#(A)
data = cur.fetchone()
print(data)
#(B)
cur.roecount()
#(C)
data = cur.fetchall()
for i in data :
print(i)
mydb.close()
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )