RE: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog
From: Ron Reidy (Ron.Reidy_at_arraybiopharma.com)
Date: 03/22/05
- Previous message: Sunil A.V.: "Re: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Maybe in reply to: Ron Reidy: "RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Next in thread: Bill Costa: "RE: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Reply: Bill Costa: "RE: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 22 Mar 2005 11:38:37 -0700 To: "Sunil A.V." <sunilav@rediffmail.com>
Not so strange ... look at the code: " ... DBI->connect($dsn, $user, $pass, {AutoCommit => 0}) || undef;"
You are returning undef. You need to print the DBI::errstr at the very least.
The fact your code executes from the command line and not the web server indicates either a permissions problme or an environment problem. Here is a google search that may help you:
http://forums.devshed.com/archive/t-123883/Connection-problem-with-Oracle-only-in-browser
-----------------
Ron Reidy
Lead DBA
Array BioPharma, Inc.
303.386.1480
-----Original Message-----
From: Sunil A.V. [mailto:sunilav@rediffmail.com]
Sent: Tuesday, March 22, 2005 11:32 AM
To: Reidy, Ron
Cc: Tim.Bunce@pobox.com; dbi-users@perl.org
Subject: Re: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog
Strangely it is not giving any error. When I see the web server's log, it has no errors. Any other place to see for errors?
I gave some prints after connect statement. The db handle returned by db_connect is null or blank. So it prints blank. I also printed $dsn, $user, etc to verify the function is being called and has correct values.
I re-checked that all file permissions are 777
On what conditions might DBI->Connect give null or blank?
On Tue, 22 Mar 2005 Reidy,Ron wrote :
>Your connect() is failing. What is the error? My guess is there is a permissions problem on the server.
>
>-----------------
>Ron Reidy
>Lead DBA
>Array BioPharma, Inc.
>
>
>-----Original Message-----
> From: Sunil A.V. [mailto:sunilav@rediffmail.com]
>Sent: Tuesday, March 22, 2005 10:30 AM
>To: dbi-users@perl.org
>Cc: Tim.Bunce@pobox.com
>Subject: DBI->Connect returning UNDEF in cgi but not in standalone prog
>
>
>Hi,
>
>I am trying to connect to database for my web application based on perl cgi and getting problems.
>
>I have a utility function for the purpose. The wierd thing is when I call the utility function from my cgi program, it is returning UNDEF and so not working. If I call the same function from another standalone perl program, the function is retuning the proper db handle through which I am able to connect to db and do db stuff.
>Anything I am missing? Should the web based way of calling should be any different?
>
>Standalone prog results: prints the count of table properly
>index.cgi gives "Can't call method "prepare" on an undefined value"
>
>Note : programs below
>
>Thanks,
>Sunil
>
>
>
>Call_New.pl [standalone- working]
>===========
>use myapp_utility;
>print authorized_user('myuserid');
>
>
>
>index.cgi [First page of my web application- not working]
>==========================================================
>use lib ("/opt/iplanet/cgi-bin/myapp");
>unshift(@INC, ".","/opt/iplanet/cgi-bin/myapp");
>use CGI qw(:standard :html3);
>use CGI::Carp qw(fatalsToBrowser);
>use myapp_utility;
>if(authorized_user('myuserid')) {
> dispay_page();
>} else {
> display_error_page();
>}
>
>
>
>myapp_utility.pm [utility package]
>================================
>use CGI qw(:standard :html3);
>use DBD::Oracle qw(:ora_types);
>use DBI;
>$^W = 1; # all objects *must* be -w clean
>
>require Exporter;
>use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
>
>$VERSION = 0.01;
>
># inheritance heirarchy
>@ISA = qw(Exporter);
>
>@EXPORT = qw
>(
> authorized_user
>)
>use vars qw
>(
> &authorized_user
>)
>
>###############################################################################
># NAME OF THE SUB-ROUTINE: db_connect
># INPUT PARAMETERS : None
># FUNCTION : Creates a connection with the database and returns
># the database handle
>###############################################################################
>sub db_connect
>{
>$g_myapp_database_schema = 'myapp';
>
>$ENV{'ORACLE_HOME'} = '/opt/oracle/product/9.2.0.6.0_64c';
>$G_db_connect_string = 'dbi:Oracle:ledmyapp';
>$G_db_user = 'myapp';
>$G_db_passwd = 'xxxxx';
> my $dsn = shift || ($G_db_connect_string ? $G_db_connect_string : undef);
> my $user = shift || ($G_db_user ? $G_db_user : undef);
> my $pass = shift || ($G_db_passwd ? $G_db_passwd : undef);
> my $db_handle;
> $db_handle = DBI->connect($dsn, $user, $pass, {AutoCommit => 0}) || undef;
> return $db_handle;
>}
>
>###############################################################################
># NAME OF THE SUB-ROUTINE: db_disconnect
># INPUT PARAMETERS : $db_handle
># OUTPUT PARAMETERS : 1/0
># FUNCTION : Receives a database handle and closes the database
># connection
>###############################################################################
>sub db_disconnect
>{
>$g_myapp_database_schema = 'myapp';
>
>$ENV{'ORACLE_HOME'} = '/opt/oracle/product/9.2.0.6.0_64c';
>$G_db_connect_string = 'dbi:Oracle:ledmyapp';
>$G_db_user = 'myapp';
>$G_db_passwd = 'xxxxx';
> my $db_handle = shift;
> my $rc;
> if(defined $db_handle)
> {
> $rc = $db_handle->disconnect;
> }
>
> return $rc;
>}
>
>###############################################################################
># NAME OF THE SUB-ROUTINE: authorized_user
># INPUT PARAMETERS : $user
># OUTPUT PARAMETERS : 1/0
># FUNCTION : Authenticates user in the myapp database
># Returns 1 if user is authenticated
># Returns 0 if user is invalid
>###############################################################################
>sub authorized_user
>{
>
>$ENV{'ORACLE_HOME'} = '/opt/oracle/product/9.2.0.6.0_64c';
>$G_db_connect_string = 'dbi:Oracle:ledmyapp';
>$G_db_user = 'myapp';
>$G_db_passwd = 'xxxxx';
> my $user = shift;
> my $g = db_connect();
> my $sql = qq
> {
> SELECT
> COUNT(*)
> FROM
> myapp_USER
> };
> my $sth = $g->prepare($sql);
> unless ($sth)
> {
> $main::G_database_error = 1;
> return 0;
> }
> unless ($sth->execute())
> {
> $main::G_database_error = 1;
> return 0;
> }
> my $user_authorization;
> $sth->bind_columns(\$user_authorization);
> $sth->fetch();
> $sth->finish();
> if(defined $g) {
> $g->disconnect();
> }
> return $user_authorization;
>}
>
>This electronic message transmission is a PRIVATE communication which contains
>information which may be confidential or privileged. The information is intended
>to be for the use of the individual or entity named above. If you are not the
>intended recipient, please be aware that any disclosure, copying, distribution
>or use of the contents of this information is prohibited. Please notify the
>sender of the delivery error by replying to this message, or notify us by
>telephone (877-633-2436, ext. 0), and then delete it from your system.
>
<http://clients.rediff.com/signature/track_sig.asp>
This electronic message transmission is a PRIVATE communication which contains
information which may be confidential or privileged. The information is intended
to be for the use of the individual or entity named above. If you are not the
intended recipient, please be aware that any disclosure, copying, distribution
or use of the contents of this information is prohibited. Please notify the
sender of the delivery error by replying to this message, or notify us by
telephone (877-633-2436, ext. 0), and then delete it from your system.
- Previous message: Sunil A.V.: "Re: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Maybe in reply to: Ron Reidy: "RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Next in thread: Bill Costa: "RE: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Reply: Bill Costa: "RE: RE: DBI->Connect returning UNDEF in cgi but not in standalone prog"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|