in reply to Output of CGI with DBI

Your web server usually executes as a different user and with a different environment as you on the command line.

In your case it could be that $dbh is undef because the web server couldn't connect to the database. So better check those return values, especially if you turned off any error-raising as you seem to have done

PS: Please 'use warnings' at a minimum, 'use strict' is also advisable

Replies are listed 'Best First'.
Re^2: Output of CGI with DBI
by brp4h (Acolyte) on Jul 08, 2010 at 19:07 UTC
    Thanks, roboticus and jethro. I fixed my issue by setting the environment variables for DB2_PATH, DB2INSTANCE, and SQLLIB in the script to the correct values.
Re^2: Output of CGI with DBI
by brp4h (Acolyte) on Jul 08, 2010 at 17:25 UTC
    Thanks... I guess by command line I meant I'm sshing into the web server and running the CGI script and get the correct output, so I thought the environment would be the same. I tried checking the return values, but I can't get ANY sort of output from the web after the connection should be established.

      brp4h:

      You can definitely ssh into the webserver, but for it to do you any good, you have to ssh into it using the same account that the webserver is running. Otherwise, it will have its own path and other environment variables. Heck, it could even be running a different perl than your account. So unless you're running under the webserver account, running it at the command line won't tell you much.

      ...roboticus

        Thanks, roboticus. The DB connection fails with this message: Total Environment allocation failure! Did you set up your DB2 client environment? That's because the webserver account doesn't have the client enviroment set up, even though my account on the webserver does?