Monday, February 11, 2019

Reading From Database Using Python

After inserting the records into our database table, it is only expected that we should read from the table using our Python code.

Our database table EMPLOYEE looks like this:

You can display ALL the entries of your table below:

The fechall() will actually read all the records from your table. Using the loop, each of the record will be displayed.  The row[0], for instance, acts as the variable to hold the value of the first field(using our table above, First_Name), and row[1] will be be for our field Last_Name.

Don't forget that the Python code above is a function. If you don't have a main menu, then, simply call this module by typing, read( ), in your main code.

To search and display a specific record from the table, your Python code should be like this. You can double click to enlarge the photo.

Now, try this on other tables you have!