這章省略太多,由於對前面的代碼修改了不少,主要將數據處理移到使用數據庫,後面學完再回頭來看。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.