Re: Failed to use Pro *C to write CGI program ?

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 15 Oct 1999 08:40:20 -0400
Message-ID: <6h8HOIjwsIC2GeuKiBFDqvN0gpmQ_at_4ax.com>


A copy of this was sent to Eric Chow <eric138_at_yahoo.com> (if that email address didn't require changing) On Fri, 15 Oct 1999 15:26:00 +0800, you wrote:

>Hello,
>
>I tried to use Pro *C to write a simple CGI program, but it failed when
>I executed in browsers.
>The following is the source code :
>-------------------------
>#include <stdio.h>
>EXEC SQL INCLUDE SQLCA;
>int main() {
> char db[] = "user/pass_at_db";
> int result;
>
> EXEC SQL CONNECT :db;
>
> EXEC SQL SELECT count(*) INTO result FROM testDB;
> /* output to the WEB */
> printf("Content-type: text/html\n");
> printf("<html><body>Result = %d</body></html>\n", result);
> return 1;
>}
>----------------------------
>The above program can compile successfully and can be executed very well
>in command prompt in Sun Solaris 2.6.
>After I put the executable file in cgi-bin, and load in in browser.
>It can't display anything justpop out a window with "This document
>contains no data....". And then I remove all the embed SQL just leaving
>the standard C statements, it can be loaded well in browser.
>
>Would you please to teach me how can I use C(Pro *C) to write CGI
>program ??
>Or is there any other method to connect to Oracle in C ?????
>

cgi-bin apps run in a pristine environment.

you are missing important environment variables like:

LD_LIBRARY_PATH
ORACLE_HOME
ORACLE_SID
PATH and so on. The program (if dynamically linked) probably isn't even loading (hence the "document contains no data") because ld.so is complaining that libclntsh.so or something cannot be found (and it puts this to stderr, not stdout so you never see it).

Try this -- if your web server runs cgi-bin as user NOBODY (typical).

  1. su -
  2. su - nobody
  3. run your cgi-bin program.

Now, setup the environment so your program CAN run and print results. Remember what environment variables you set. then either:

  • convince your webserver to pass these variables to your Cgi-bin, method varies by webserver.
  • create a script that looks like:

#!/bin/sh
LD_LIBRARY_PATH=....
ORACLE_HOME=....
....
export LD_LIBRARY_PATH
export ORACLE_HOME
....
exec YOUR_PROGRAM

and run the sh script instead of your program as the cgi-bin.

>Best regards,
>Eric
>

-- 
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st
 
Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation
Received on Fri Oct 15 1999 - 14:40:20 CEST

Original text of this message