The method of reading database data in python operation database
Automated tests often write data to the database and then read it from the database.
Here's how to read data from a database.
Prerequisite: mysql.connector module is installed
The established database is (under the tet table of the test database):
Use fetchone () to get the next row of the result set
The values read after running are:
If you add a statement C = fetchone () directly after D, C will be the next value in the list:
The value of C obtained is:
And so on, continuing with fetchone will continue to read the next row of data in the result set.
Use fetchall () to get all the remaining rows in the result set
The values read after running are:
Third, use fetchmany () to get the lower line of the result set (specify how many rows of data are printed)
The running result will get 2 rows of data results:
There is a problem QQ × × stream 610845268