Home: Perl Programming Help: DBI:
Problems whit DBI Interfase



abelsgmx
Novice

Jun 6, 2002, 11:19 AM


Views: 15506
Problems whit DBI Interfase

How to do a SELECT MAX statement, I haev have problems whit this code:


Code
$dbh = DBI->connect ($dsn, $usr, $pwd, {RaiseError => 1}); 
$sth = $dbh->prepare ("
SELECT max(id_age) as id_age
FROM teachers
");
$sth->execute ;
$id_age = $sth->fetchrow_array;
$sth->finish;
$dbh->disconnect;


This don't return the max value, some one know how do for this?, thanks a lot!!!
Crazy


Jean
User


Jun 13, 2002, 1:01 AM


Views: 15498
Re: [abelsgmx] Problems whit DBI Interfase

I'm not sure this is the issue here, but I'll try anyway...

fetchrow_array() returns an array and when you're assigning its value to a scalar, you get the number of elements of the array. You probably want to use

$id_age = ($sth->fetchrow_array);

This way you'll get the first element of the array into $id_age.

Hope this helps...


Jean Spector
SQA Engineer @ Exanet
jean.spector@softhome.net


There are only 10 types of people in the world -
Those who understand binary, and those who don't.


abelsgmx
Novice

Jul 18, 2002, 7:00 PM


Views: 15479
Re: [Jean] Problems whit DBI Interfase

Thanks a lot, this was so helpull!!!


Jean
User


Jul 20, 2002, 10:58 PM


Views: 15468
Re: [abelsgmx] Problems whit DBI Interfase

I'm glad it was Wink


Jean Spector
SQA Engineer @ Exanet
jean.spector@softhome.net


There are only 10 types of people in the world -
Those who understand binary, and those who don't.


Paul
Enthusiast

Jul 22, 2002, 3:36 AM


Views: 15465
Re: [Jean] Problems whit DBI Interfase

Or:

my ($id_age) = $sth->fetchrow;


Jean
User


Jul 22, 2002, 3:41 AM


Views: 15463
Re: [RedRum] Problems whit DBI Interfase

Cool Cool Cool


Jean Spector
SQA Engineer @ Exanet
jean.spector@softhome.net


There are only 10 types of people in the world -
Those who understand binary, and those who don't.


abelsgmx
Novice

Jul 23, 2002, 5:52 PM


Views: 15453
Re: [Jean] Problems whit DBI Interfase

Thanks a lot!!