ich nutze einen Hosting-Dienst bei Celeros und habe kürzlich die folgenden code im Ordner /html/cgi-bin ausgeführt:
Code: Alles auswählen
#!/usr/bin/python
import sys
print "Content-type: text/html"
print ""
print sys.version_info
Code: Alles auswählen
sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)
Code: Alles auswählen
#!/usr/bin/python
# database-functionality
import sqlite3
import cgitb
cgitb.enable()
# class DataBase
# management of any type of sqlite3-database
class DataBase:
def __init__(self, filePath="/data/database.dat"):
self.__connect = sqlite3.connect(filePath)
self.__cursor = self.__connect.cursor()
def __del__(self):
self.__connect.commit()
self.__cursor.close()
self.__cursor.close()
# add a new table
def addTable(self, name, format):
command = "CREATE TABLE "
command += (name + "(id")
for formatName in format:
command += ","
command += formatName
command += ")"
self.__cursor.execute(command)
self.__connect.commit()
# return whole table as list of tuples
def getTable(self, table):
pass
# delete whole table
def delTable(self, table):
self.__cursor.execute("DROP TABLE " + table)
self.__connect.commit()
# clear (delete all items) a table
def clearTable(self, table):
self.__cursor.execute("TRUNCATE TABLE " + table)
self.__connect.commit()
# add element in table
def addElement(self, table, element):
command = "INSERT INTO "
command += (table + " VALUES (?")
for i in range(len(element) - 1):
command += ",?"
command += ")"
self.__cursor.execute(command, element)
self.__connect.commit()
# get only one element by its ID
def getElementById(self, id):
pass
# delete element in table
def delElement(self, id):
pass
db = DataBase("database.dat")
db.addTable("personen", ("firstname", "lastname"))
db.addElement("personen", (1, "Martina", "Mueller"))
print("fertig")
Kann mir hier jemand weiterhelfen? Ich weiß mir keinen Rat.
Danke,
Diddus