[Tutor] Re: Question on open and read html files and psycopg
Lee Harr
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.
>Because,
>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")
print my_query
# It seems that we need to have an appropriate username that matches
# an entry in the postgresql table of users.
import os
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...
import psycopg
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*
http://join.msn.com/?page=features/virus
More information about the Tutor
mailing list