python session 10

Post on 13-May-2015

50 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Python -DB connectivity

TRANSCRIPT

WELCOME TO PYTHON SESSION 10WELCOME TO PYTHON SESSION 10

AGENDA

Database Connection

What is Cursor.

What is the uses of MySQLdb in python.

Database Connection

Creating Database Table

Insert Operation

Delete Operation

Read Operation Once our database connection is established, we are ready to make a query into this database.

Fetchone():

This method fetches the single row of a query result set. A result set is an object that is returned when a cursor object is used to query a table.

Fetchall():

This method fetches all the rows in a result set. If some rows have already been extracted from the result set, the fetchall() method retrieves the remaining rows from the result set.

Rowcount:

This is a read-only attribute and returns the number of rows that were affected by an execute() method.

Example

Inserting Images

The dictionary cursor

There are multiple cursor types in the MySQLdb module.

The default cursor returns the data in a tuple of tuples.

When we use a dictionary cursor, the data is sent in a form

of Python dictionaries. This way we can refer to the data by

their column names.

Example

Connection ObjectsCOMMIT Operation:

Commit is the operation, which gives a green signal to database to finalize the changes, and after this operation, no change can be reverted back

db.commit()

ROLLBACK Operation:

If you are not satisfied with one or more of the changes and you want to revert back those changes completely, then use rollback() method.

db.rollback()

Connection ObjectsCOMMIT Operation:

Commit is the operation, which gives a green signal to database to finalize the changes, and after this operation, no change can be reverted back

db.commit()

ROLLBACK Operation:

If you are not satisfied with one or more of the changes and you want to revert back those changes completely, then use rollback() method.

db.rollback()

THANK YOU

Reference

Reference Link:

http://www.tutorialspoint.com/python/python_database_access.htm

top related