Day 1 - 12 A C Ls - 8 - Interface Python With SQL 2024 - 2025
Day 1 - 12 A C Ls - 8 - Interface Python With SQL 2024 - 2025
Ls – 8
Interface Python with SQL
SYLLABUS:
• Interface of Python with an SQL database
• Connecting SQL with Python
• Performing Insert, Update, Delete queries using cursor
• Display data by using fetchone(),fetchall(),rowcount
• Creating Database connectivity Applications
passwd /password
Write from
next page
NB:
➢ connect ( ) function establishes a connection to the MySQL database from Python Application and returns a
MySQLConnection Object (mydb).
➢ This MySQLConnection Object (mydb) is used to perform various actions on the Database.
➢ To know the current user ; check in mysql >select current_user();
MySQL Connection Object Host Name – the server name or IP address on which
Used to perform actions on MySQL is running
the Database. Username – the username that you use to work with MySQL
Server (Default : root)
Password – Password is given by the user at the time of
installing the MySQL database .
➢ cursor( ) is a control statement to traverse over records in a database. It is used to fetch results of the
query.
➢ Cursor is used to traverse the records from the result set.
➢ Cursor stores all the data as a temporary container of returned data and we can fetch data one row at a time
from Cursor.
➢ An arbitrary number of cursors can be created.
➢ execute( ) function is used to send SQL query to a connection.
cursor_name.execute(query)
Eg: - mycursor.execute(‘show databases’)
6. Terminate connection to db
➢ connection.close()
• To terminate the MySQL database connection.