我有一个包含名字、姓氏、年龄和性别的表格。现在如何使用 python 将数据插入伯克利数据库?我对这种数据库真的很陌生。大多数数据库都有要关联的 sql 查询和用于获取和获取数据的游标。但在伯克利,就没有这样的情况。
我已经阅读了有关 Berkeleys db 的信息,但我没有得到它。任何帮助表示赞赏
我正在使用 Python 2.5
我如何将这些来自表单的数据集成到伯克利数据库中?
当我在服务器上运行时出现一些错误:
File "/usr/lib/python2.5/bsddb/__init__.py", line 306, in hashopen, referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] , referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] d.open(file, db.DB_HASH, flags, mode), referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] bsddb.db, referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] ., referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] DBAccessError, referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] : , referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] (13, 'Permission denied'), referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] , referer: http://192.168.2.181/~jeremy/index.html
[Fri Nov 08 17:26:55 2013] [error] [client 192.168.2.181] Premature end of script headers: database.py, referer: http://192.168.2.181/~jeremy/index.html
代码:
#!/usr/bin/python
import bsddb
import cgi
form = cgi.FieldStorage()
Fname = form.getvalue('firdtname')
Lname = form.getvalue('lastname')
Age = form.getvalue('age')
Gender = form.getvalue('gender')
db = bsddb.hashopen("/tmp/mydb.db","c")
db['FirstName'] = Fname
db['Lastname'] = Lname
db['Age'] = Age
db['Gender'] = Gender
db = bsddb.hashopen("/tmp/mydb.db")
print db['FirstName'], db['Lastname'], db['Age'], db['Gender']
db.close()
print "Content-type:text/html\n"