database Query Operations
Python queries MySQL uses the Fetchone () method to get a single piece of data, using the Fetchall () method to get multiple data.
Fetchone (): This method gets the next query result set. The result set is an object fetchall (): Receives all the returned result rows. RowCount: This is a read-only property and returns the number of rows affected after the Execute () method is executed.
Fetchone ():
Returns a single tuple, which is a record (row), and returns none if no result is found
Fetchall ():
Returns multiple tuples, which returns multiple records (rows) and returns if no result ()
Note: null in MySQL, and none in Python
the usage is as follows: Fetchone () Usage: Cur.execute ("Select Host,user,password from user where user= '%s '"%ACC) Jilu= Cur.fetchone ()##此时 via jilu[0],jilu[1],jilu[2] to access Host,user,passwordfetchall () Usage: Cur.execute ("SELECT * from user"If the select itself takes more than one piece of data: Cursor.fetchone (): Takes only the first result of the top and returns a single tuple such as ('ID','title'), and then use Cursor.fetchone () multiple times to get the next result until it is empty. Cursor.fetchall (): Returns all results, returning a two-dimensional tuple, such as ('ID','title'),('ID','title') , if the select itself takes only one piece of data: Cursor.fetchone (): Returns only one result, returning a single tuple such as ('ID','title'). Cursor.fetchall (): will also return all results, returning two-dimensional tuples, such as (('ID','title'), note: Where the ID and title are specific to the content of Python in MySQL when using Fetchall or Fetchone, together, Fetchall returns a two-dimensional tuple (tuples containing tuples), Fetchone only returns one-dimensional tuples.
Database query Operations (FETCHONE,FETCHALL)