这章省略太多,由于对前面的代码修改了不少,主要将数据处理移到使用数据库,后面学完再回头来看。web
“数据库API” —— 这是一种标准化机制,用于从Python程序访问一个基于SQL的数据库系统。sql
(看起来比JDBC容易使用。)数据库
不论使用的后台数据库是什么,代码所遵循的过程都是同样的:code
链接 -> 建立(游标) -> 交互 -> 提交或回滚 -> 关闭(链接)server
经常使用代码:sqlite
Python包括SQLite图片
The fieldStorage()
method from the standard library’s cgi module lets you access data sent to your web server from within your CGI script.ip
The standard os library includes the environ dictionary providing convenient access to your program’s environment settings.it
The SQLite database system is included within Python as the sqlite3 standard library.io
The connect() method establishes a connection to your database file.
The cursor() method lets you communicate with your database via an existing connection.
The execute() method lets you send an SQL query to your database via an existing cursor.
The commit() method makes changes to your database permanent.
The rollback() method cancels any pending changes to your data.
The close() method closes an existing connection to your database.
The “?” placeholder lets you parameterize SQL statements within your Python code.