1.Chap 15 Interfacing Python with MySQLA (1)
1.Chap 15 Interfacing Python with MySQLA (1)
05
Installing MySQL Program to create
02
driver database
import mysql.connector
# A database cursor is a special control structure that facilitates the row by row
processing of records in the result set, i.e. the set of records retrieved as per the
query.
cursor=mycon.cursor()
#Once you have created a cursor, you need to execute SQL query using execute()
function with cursor object.
# A ResultSet refers to a logical set of records that are fetched from the database
by executing an SQL Query and made available to the application program.
We can extract data from ResultSet using any of the following fetch…() function.
1. fetchall() : it will return all the rows from the resultset in the form of tuple
containing the records.
data=cursor.fetchall()
for row in data: # it will extract one row at a time and display it
print (row)
data= cursor.fetchone()
while(data):
print(data)
data= cursor.fetchone()
3. fetchmany(N): it will return specified number of rows at a time from resultset.
data= cursor.fetchmany(N)
print(data)
or
After you are through all the processing, in this final step you need to close the
environment.
mycon.close()
Ouput
Ouput
Before execution of the
program