Interface Python With SQL
Interface Python With SQL
CLASS-XII
Interface python with SQL DB
All companies
whether large or
small use data bases.
So it become
necessary to develop
project/software
using any
programming
language like python in such a manner which can interface
with such databases which support SQL
Steps to connect python to
MySQL DB
1. Install MySQL connector drivers.
2. Import Mysql . connector module
3. Create a connection object.
4. Create a cursor instance.
5. Execute a query.
6. Extract data from the resultset.
7. Clean up the environment.
Connecting to MySQL From Ptyhon
MySQL python connector :- To access the MySQL database
from python, you need a database driver. Mysql connector is
a standardize database driver provided by MySQL.
Syntax - <cur_obj>=conn.cursor()
Output:
Cursor.rowcount()
•It will display no of records fetched after running.
More Functions
▪cursor . fetchall(): fetches all the rows of a query result. it
returns all the rows as a list of tuples.An empty list is
returned if there is no record to fetch.
mycursor. Close()
Performing insert and update queries
Always commit() after executing insert and update
queries. Syntax:-
connectionboject.commit()
1.INSERT:
Performing insert and update queries
2.UPDATE