In using Class::DBI::mysql to get some data from a single table using the code fragment below:
I find I get no output printed. This is wierd! So I went back to the documentation and could find nothing. Then I recalled that when I first looked at Class::DBI I tried the code from Class::DBI Intro by trs80. Now in there I read:sub en_display { # Display 'full signup or enroll' form my $self = shift; my $errs = shift; my $output =''; my $sess = $self->param('up_session'); if ( $sess->param('_IS_USER') && $sess->param('_IS_REGISTERED') ) +{ my $obj = AppSys::User->search( 'upusername' => $sess->param(' +_IS_USER')); while ( my $usr = $obj->next ) { #$output .= "Username: " . $usr->upusername . "<br><br>"; foreach ( $usr->columns ) { $output .= "<b>$_</b>; $usr->{$_} <br>"; } } } return $output;
Which is just what I did and, yes, he is right! In my own code at the top of the page if I uncomment the line #$output .= "Username: " . $usr->upusername . "<br><br>"; I get the expected output.# now we will make an object that relates to a single # record. We know that our entry is id 1 since it is # the only record in the database so we do the following our $user = Table::User->retrieve(1); # $user contains our object, but since we haven't called # any methods on the objects it has not made any calls to # the database. print ">> Class::DBI Results (single column)\n"; print " Users First Name: " , $user->first_name , "\n\n"; # Now $user contains all the information related to # the record in the database. You can verify this with # Data::Dumper if you want.
Why do I need this apparently redundant method call to get the data into the object? Is there some way of ensuring that the data is loaded without the additonal call?
In reply to Class::DBI strangeness... by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |