Page 94 - PYTHON-12
P. 94
except:
db1.rollback()
db1.close()
Fetching all the records from EMP table having salary more than 70000.
import MySQLdb
db1 = MySQLdb.connect("localhost","root","","TESTDB" )
cursor = db1.cursor()
sql = "SELECT * FROM EMP WHERE SALARY > 70000;"
try:
cursor.execute(sql)
#using fetchall() function to fetch all records from the table EMP and store in
resultset
resultset = cursor.fetchall()
for row in resultset:
print (row)
except:
print ("Error: unable to fetch data")
db1.close()