SlideShare a Scribd company logo
1 of 26
INTERF
ACEPYTHONWITH
MYSQL
ConnectingPythonapplication with MySQL
Introduction
 Every application required data to be stored for future
reference to manipulate data. Today every application
storesdata in database for this purpose
 For example, reservation system stores passengers
details for reserving the seats and later on for sending
somemessagesor for printing tickets etc.
 Python allows us to connect all types of database like
Oracle, SQLServer, MySQL.
Pre-requisite to connectPythonwith
MySQL
 Before we connect python program with any database
like MySQL we need to build a bridge to connect
PythonandMySQL.
 T
obuild thisbridge sothat data cantravel both ways we
need a connectorcalled “mysql.connector”.
 We can install “mysql.connector” by using following
methods:
At commandprompt (Administrator login)
 Type“pip install mysql.connector”and press enter
 (internet connectionin required)
 Thisconnector will work only for MySQL5.7.3 orlater
Or open
“https://dev.mysql.com/downloads/connector/python/”
Connectingto MySQLfrom Python
 Oncethe connectorisinstalled youare ready to
connectyour python program to MySQL.
 Thefollowing stepsto follow while connectingyour
python program with MySQL
Open python
Import the package required (import mysql.connector)
Open the connectionto database
Create a cursor instance
Executethe query and store it in resultset
Extract data from resultset
Clean up the environment
Importing mysql.connector
import mysql.connector
Or
import mysql.connectoras ms
Here“ms”isan alias, soevery time wecanuse“ms”in
place of “mysql.connector”
Open a connection toMySQL Database
 T
ocreate connection,connect()function isused
 Itssyntaxis:
connect(host=<server_name>,user=<user_name>,
passwd=<password>[,database=<database>])
 Here server_namemeansdatabase servername, generally
it isgiven as“localhost”
 User_namemeansuserby whichwe connectwith mysql
generally it isgiven as “root”
 Passwdisthe password of user“root”
 Database isthe nameof database whosedata(table) we
want to use
Example: Toestablish connection with MySQL
is_connected() function returns
true if connection isestablished
otherwise false
“mys” isan alias of package “mysql.connector”
Creating Cursor
 It isa usefulcontrol structure of database connectivity.
 When we fire a query to database, it is executed and
resultset (set of records) is sent over theconnectionin one
go.
 We may want to access data one row at a time, but
query processing cannot happens as one row at a time,
socursor help usin performing this task. Cursor stores all
the data as a temporary container of returned data
and wecanfetch data onerow at a time from Cursor.
Creating Cursor and Executing Query
 TO CREATE CURSOR
Cursor_name= connectionObject.cursor()
For e.g.
mycursor= mycon.cursor()
 TO EXECUTE QUERY
 We useexecute()function to sendquery to connection
 Cursor_name.execute(query)
 For e.g.
 mycursor.execute("select* from emp")
Example- Cursor
Output shows cursor is created and query is fired and stored, but no data is
coming. T
o fetch data we have to use functions like fetchall(), fetchone(),
fetchmany() are used
Fetching(extracting) data from ResultSet
 T
oextract data from cursorfollowing functionsare used:
fetchall() :it will return all the record in the form of listof
tuples.
fetchone() : it return one record from the result set. i.e.
first time it will return first record, next time it will return
second record and so on. If no more record it will return
None
fetchmany(n) : it will return n number of records. It no
morerecord it will return an empty list.
rowcount : it will return number of rows retrieved from
the cursorsofar.
Table to work (emp)
Example– fetchall()
Example4: fetchone()
Example5: fetchmany(n)
Parameterized Query
 We can pass values to query to perform dynamic
search like we want to search for any employee
number entered during runtime or to search any
other column values.
 T
o Create Parameterized query we can use various
methods like:
Concatenating dynamic variable to query
valuesare entered.
String template with % formatting
String template with {} and format function
in which
Concatenating variable with query
String template with %sformatting
 Inthismethodwewill use%sin place of valuesto
substituteand thenpassthe value for that place.
String template with %sformatting
String templatewith {} and format()
 Inthis method in place of %swe will use{} and to pass
valuesfor theseplaceholder format() isused. Insidewe
canoptionally give 0,1,2… valuesfor e.g.
{0},{1} but its not mandatory. we can also optionally
passnamedparameter inside {} sothat whilepassing
we need
to pass.
of
value
not to
For e.g.
values through format function
remember the order
{roll},{name} etc.
String templatewith {} and format()
String templatewith {} and format()
Inserting data in MySQL table from Python
 INSERT, UPDATE AND DELETE operation are
executed in the same way we execute SELECTquery
using execute() but one thing to remember, after
executing insert or update query we must commit
our query using connectionobjectwith commit().
 Fore.g. (if our connectionobject nameis mycon)
 mycon.commit()
Example: inserting data
BEFORE PROGRAM EXECUTION
AFTER PROGRAM EXECUTION
Example: Updating record

More Related Content

Similar to Interface Python with MySQL connectivity.pptx

Interfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptxInterfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptxcavicav231
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorialinfo_zybotech
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxfacebookrecovery1
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technologyfntsofttech
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questionssubash01
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsphanleson
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbcphanleson
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Databasedharawagh9999
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questionssekar c
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...TAISEEREISA
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 

Similar to Interface Python with MySQL connectivity.pptx (20)

Interfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptxInterfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptx
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
 
24. SQL .pdf
24. SQL .pdf24. SQL .pdf
24. SQL .pdf
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptx
 
Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
 
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP TechnologyFnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
Fnt Software Solutions Pvt Ltd Placement Papers - PHP Technology
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Data structures
Data structuresData structures
Data structures
 
Unit 2 web technologies
Unit 2 web technologiesUnit 2 web technologies
Unit 2 web technologies
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
 
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
Chapter 3.pptx Oracle SQL or local Android database setup SQL, SQL-Lite, codi...
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

Interface Python with MySQL connectivity.pptx

  • 2. Introduction  Every application required data to be stored for future reference to manipulate data. Today every application storesdata in database for this purpose  For example, reservation system stores passengers details for reserving the seats and later on for sending somemessagesor for printing tickets etc.  Python allows us to connect all types of database like Oracle, SQLServer, MySQL.
  • 3. Pre-requisite to connectPythonwith MySQL  Before we connect python program with any database like MySQL we need to build a bridge to connect PythonandMySQL.  T obuild thisbridge sothat data cantravel both ways we need a connectorcalled “mysql.connector”.  We can install “mysql.connector” by using following methods: At commandprompt (Administrator login)  Type“pip install mysql.connector”and press enter  (internet connectionin required)  Thisconnector will work only for MySQL5.7.3 orlater Or open “https://dev.mysql.com/downloads/connector/python/”
  • 4. Connectingto MySQLfrom Python  Oncethe connectorisinstalled youare ready to connectyour python program to MySQL.  Thefollowing stepsto follow while connectingyour python program with MySQL Open python Import the package required (import mysql.connector) Open the connectionto database Create a cursor instance Executethe query and store it in resultset Extract data from resultset Clean up the environment
  • 5. Importing mysql.connector import mysql.connector Or import mysql.connectoras ms Here“ms”isan alias, soevery time wecanuse“ms”in place of “mysql.connector”
  • 6. Open a connection toMySQL Database  T ocreate connection,connect()function isused  Itssyntaxis: connect(host=<server_name>,user=<user_name>, passwd=<password>[,database=<database>])  Here server_namemeansdatabase servername, generally it isgiven as“localhost”  User_namemeansuserby whichwe connectwith mysql generally it isgiven as “root”  Passwdisthe password of user“root”  Database isthe nameof database whosedata(table) we want to use
  • 7. Example: Toestablish connection with MySQL is_connected() function returns true if connection isestablished otherwise false “mys” isan alias of package “mysql.connector”
  • 8. Creating Cursor  It isa usefulcontrol structure of database connectivity.  When we fire a query to database, it is executed and resultset (set of records) is sent over theconnectionin one go.  We may want to access data one row at a time, but query processing cannot happens as one row at a time, socursor help usin performing this task. Cursor stores all the data as a temporary container of returned data and wecanfetch data onerow at a time from Cursor.
  • 9. Creating Cursor and Executing Query  TO CREATE CURSOR Cursor_name= connectionObject.cursor() For e.g. mycursor= mycon.cursor()  TO EXECUTE QUERY  We useexecute()function to sendquery to connection  Cursor_name.execute(query)  For e.g.  mycursor.execute("select* from emp")
  • 10. Example- Cursor Output shows cursor is created and query is fired and stored, but no data is coming. T o fetch data we have to use functions like fetchall(), fetchone(), fetchmany() are used
  • 11. Fetching(extracting) data from ResultSet  T oextract data from cursorfollowing functionsare used: fetchall() :it will return all the record in the form of listof tuples. fetchone() : it return one record from the result set. i.e. first time it will return first record, next time it will return second record and so on. If no more record it will return None fetchmany(n) : it will return n number of records. It no morerecord it will return an empty list. rowcount : it will return number of rows retrieved from the cursorsofar.
  • 12. Table to work (emp)
  • 16. Parameterized Query  We can pass values to query to perform dynamic search like we want to search for any employee number entered during runtime or to search any other column values.  T o Create Parameterized query we can use various methods like: Concatenating dynamic variable to query valuesare entered. String template with % formatting String template with {} and format function in which
  • 18. String template with %sformatting  Inthismethodwewill use%sin place of valuesto substituteand thenpassthe value for that place.
  • 19. String template with %sformatting
  • 20. String templatewith {} and format()  Inthis method in place of %swe will use{} and to pass valuesfor theseplaceholder format() isused. Insidewe canoptionally give 0,1,2… valuesfor e.g. {0},{1} but its not mandatory. we can also optionally passnamedparameter inside {} sothat whilepassing we need to pass. of value not to For e.g. values through format function remember the order {roll},{name} etc.
  • 21. String templatewith {} and format()
  • 22. String templatewith {} and format()
  • 23.
  • 24. Inserting data in MySQL table from Python  INSERT, UPDATE AND DELETE operation are executed in the same way we execute SELECTquery using execute() but one thing to remember, after executing insert or update query we must commit our query using connectionobjectwith commit().  Fore.g. (if our connectionobject nameis mycon)  mycon.commit()
  • 25. Example: inserting data BEFORE PROGRAM EXECUTION AFTER PROGRAM EXECUTION