Lecture on Interface of Python with an SQL Database (2)
Lecture on Interface of Python with an SQL Database (2)
CONNECTING MYSQL
WITH PYTHON
BY: ABHISHEK BHARDWAJ
PGT- COMPUTER SCIENCE
Connecting Python with MySQL
Output
Inserting Data into MySQL Table
(MySQL Connectivity)
Steps :
1. Open MySQL prompt.
2. Create Database or use an existing Database.
3. Create a New Table, if table does not exist in the selected
Database.
4. Write code in front-end language (Python) to connect, and
update data in back-end (MySQL).
5. A cursor is an object which helps to execute the query and
fetch (scoop/bring) the records from the database.
Inserting Data into MySQL Table
(MySQL Connectivity)
Write a program in Python to insert a record in MySQL Table.
Code Snippet :
rowcount function returns number of fetched rows. This function don’t have
braces ()
Extracting Data from MySQL Table
(MySQL Connectivity)
Implementation of fetchone()
Inputs : Output :
Extracting Data from MySQL Table
(MySQL Connectivity)
Implementation of fetchone() for fetching consecutive records.
Extracting Data from MySQL Table
(MySQL Connectivity)
Implementation of fetchone() for fetching consecutive records.
Inputs : Output :
Extracting Data from MySQL Table
(MySQL Connectivity)
Implementation of fetchmany() for fetching records from MySQL.