Beruflich Dokumente
Kultur Dokumente
Mayank Singh
CSE, IITGN
February 7, 2020
Two approaches
Dynamic SQL: A general-purpose program can communicate with a
database using a collection of functions at runtime.
Embedded SQL: SQL statements are identified at compile time using a
preprocessor which submits the statements to the database system for
precompilation and optimization.
Importing module
#!/usr/bin/python
import MySQLdb
Installing module
$ sudo apt-get install python-dev libmysqlclient-dev [Linux]
or
pip install MySQL-python [Python command prompt]
Connecting Database
Read Operations
fetchone(): fetches the next row of a query result set
fetchall(): fetches all the rows in a result set
rowcount(): returns the number of rows that were affected by an
execute() method
Fetchall()
A great tutorial
https://www.tutorialspoint.com/python/python_database_access.htm
A detailed introduction
http://structure.usc.edu/mysqldb/MySQLdb-3.html
A general template
An example
Declaring a cursor
Fetching tuples