Common usage of pymysql

Time:2019-12-1

The difference between cursor. Fetchone() and cursor. Fetchall():

Cursor. Fetchone(): only one data can be displayed

Cursor. Fetchall(): to display all the data found

Other common methods of pymsql

import pymysql

#Connect to database
db = pymysql.connect("localhost","admin","[email protected]","dbpymysql")

#Create a cursor object using the cursor () method
cursor = db.cursor()

#Executing SQL statements using the execute() method
cursor.execute("SELECT * FROM order_info")

#Use fetchone() to get a result data
Result = cursor. Fetchone() (only one row of results is displayed)

#Get all the result data using total()
data = cursor.fetchall()


#Close the connection between cursor and database
cursor.close()
db.close()

Update SQL
cursor.execute(sql)
db.commit()