Jasmine wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi perl gurus,
> 
> I m afraid I need some help here urgently. Could anyone see whats
> wrong with the way I query the database? Whats
> DBI::st=HASH(0x8240a10) ? Any help is appreciated Thanks!

DBI::st=HASH(0x8240a10) is the way Perl prints an object reference. $query
is a DBI statement handle (member of class DBI::st). Printing it is not
terribly useful.

> 
> the $query variable returns -->> DBI::st=HASH(0x8240a10)
> $results variable returns --> 0
> RESULTS OF QUERY: 0
> 
> 
> my $sql = "select status_id from status";
> my $query = $dbh -> prepare($sql) or die " error $! \n"; 

DBI doesn't put it's error message in $!. You need to print $DBI::errstr, or
use the PrintError or RaiseError attributes on the DBI->connect call.

> print "$query \n"; # execute the query
> $query -> execute or die "cannot execute $! \n";

Same as above.

> 
> # return the results
> my $results = $query -> fetchrow_array;

fetchrow_array returns an array, but you're calling in scalar context. If
there's only one column, you need to call it like:

   my ($results) = $query->fetchrow_array;

$results will be undef if there are no more rows to fetch, or if the column
value is null. If want to be able to tell which it was, use
fetchrow_arrayref, which returns an array reference if a row was fetched, or
undef if no more rows (or error).

> print "$results \n";
> print "RESULTS OF QUERY: $results \n";

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to