Hello monks,
i have a weird problem, i have a database module called DatosUach in this module i create a dbi handler ($self->{dbh}) and use it for common database operations.
a friend of mine is checking out CGI::Session, this module needs a dbi handler, so we (i know it's an OO aberration, but this was just a test) took it from an instance of a DatosUach object and use it on the constructor of CGI::Session. But for our surprise we got a DBI error telling us that the dbi handler we used on CGI::Session was not a valid refrence, we tried connecting using DBI->connect directly and it worked fine.
I checked the references from both handlers are the same.
Now, my question is: does this have something to do with scope?? i don't know it's very weird, excuse me if this is kind of confusing but that's how i'm feeling right now
here's the code:
sub new {
my $proto=shift;
my $class=ref($proto) || $proto;
my $myself;
my $db;
my $session;
my $myCGI;
my $sid;
my $cookie ;
my $dbh;
#my object that contains a dbi handler
$db = DatosUach::new($datos{HOST},$datos{DRIVER},$datos{D
+ATABASE},$datos{USUARIO},$datos{PASSWORD});
#direct instance of DBI
$dbh = DBI->connect(dbi:$datos{DRIVER}:dbname=$datos{DATABASE}
+;host=$datos{HOST}, $datos{USUARIO},$datos{PASSWORD});
if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
print header. "checando:";
print "<h1>REF=---".ref($db->{dbh})."---</h1>";
print "checando el otro". ref($dbh);
my $DBIHandler = $db->{dbh};
$DBIHandler->do("insert into sessions values ('1','1')");
print "Checando".ref ($DBIHandler);
$CGI::POST_MAX =1024 * 25;
$myCGI = new CGI;
$sid = $myCGI->cookie("CGISESSID") || undef;
#print header.$sid;
if (defined $sid) {
$session = new CGI::Session("driver:PostgreSQL", $sid,
+{Handle=>$db->{dbh}});
print header."Existe Sid" ;
}else{
$session = new CGI::Session("driver:PostgreSQL", undef, {H
+andle=>$db->{dbh}});
$cookie = $myCGI->cookie(CGISESSID => $session->id);
$sid = $session->id;
print $myCGI->header( -cookie=>$cookie );
print "No existe sid";
}
thanks for your help
ignorance, the plague is everywhere
--guttermouth
Edit by castaway, extra empty lines removed
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.