1、DB-API的模块属性

image.png
threadsafety线程安全级别

image.png
connection函数属性

image.png
异常类

image.png
connection类的方法:cursor

image.png
Cursor类的方法:rawcount,callproc,execute,fetchone

image.png
类型对象的构造函数:STRING, BINARY,NUMBER,DATETIME,ROWID

image.png
2、连接MYSQL数据库
mysqldb
import MySQLdb
cxn = MySQLdb.connect(user='root')
cxn.query('DROP DATABASE test')
cxn.query('CREATE DATABASE test')
cxn.query("GRANT ALL ON test.* to ''@'localhost'")
cxn.commit()
cxn.close()
cxn = MySQLdb.connect(db='test')
cur = cxn.cursor()
cur.execute('CREATE TABLE users(login VARCHAR(8), userid INT)')
cur.execute("INSERT INTO users VALUES('john', 7000)")
for data in cur.fetchall():
print '%s\t%s' % data
cxn.commit()
cxn.close()
3、postgreSQL:模块psycopg2
4、SQLite:模块sqlite3
5、ORM模块SQLAlchemy/SQLObject使用
6、mongodb模块pymongo