[Tutor] Re: Question on open and read html files and psycopg
missive at hotmail.com
Wed Sep 15 01:49:27 CEST 2004
>One more question on psycopg
>Finally, my machine is installed with psycopg and I'm wanna to try out it.
>I'm a newbie so I find it difficult to write a program that is capable of
>querying the database a
>I have a postgreSQL DB up and running, my problem is with the code. Are
>there anyone that is will
>Any help will be greatly appreciate. Thank you.
This is based on the code you posted before...
#We do have form data; just show it.
print "You typed this:"
my_query = form.getvalue("data")
# It seems that we need to have an appropriate username that matches
# an entry in the postgresql table of users.
username = os.environ.get('USER')
# print "username: ", username, type(username)
if username == None:
# Assume that the web server has started this script and has the
# username 'apache'. To allow this to access the database, we had
# to create a postgresql user of that name and have no password.
# This new user is also able to create tables and new users,
# otherwise the access seems to be blocked. (This might be a
# security problem but only for our database tables.)
username = 'apache'
# Now, we can get to the database...
db = psycopg.connect("dbname=test user=%s"%username)
qresult = db.query(my_query)
listOfResults = qresult.dictresult()
MSN 8 with e-mail virus protection service: 2 months FREE*
More information about the Tutor