Whenever something works at the command line, but doesn't
through CGI, that almost always means that you have a permissions/access
problem due to the fact that your webserver runs as a different
userid than the one you are logged in as. Find out what userid
your webserver runs as, and grant that userid privileges on
your database.