Perl / CGI / Mysql
Perl / CGI / Mysql
(OP)
Hi
I am new to Perl and CGI programming (OK, week off work and I have been playing). I have a minor problem using Mysql. I am having no problems pulling records from a database, but I cannot see how to pull the results of an SQL function. For example I want to know the latest date that certain records have been updated and have coded a "Select max(fred_date) from db_fred where fred_name = 'Smith'"
Presumably I need to return this into a result set. Up to this point I have used the syntax $ref->{'fred_name'} to retrieve the value of a field. What do I use for the result of a function?
Thanks alot
Keith
I am new to Perl and CGI programming (OK, week off work and I have been playing). I have a minor problem using Mysql. I am having no problems pulling records from a database, but I cannot see how to pull the results of an SQL function. For example I want to know the latest date that certain records have been updated and have coded a "Select max(fred_date) from db_fred where fred_name = 'Smith'"
Presumably I need to return this into a result set. Up to this point I have used the syntax $ref->{'fred_name'} to retrieve the value of a field. What do I use for the result of a function?
Thanks alot
Keith
RE: Perl / CGI / Mysql
$dbh1 = DBI->connect(connect stuff here) or die "Failed connect\n";
$sth = $dbh1->prepare("select max(fred_date) from db_fred where .....") or
die "Failed prepare, $DBI::errstr\n";
while (@row = $sth->fetchrow_array) { print "@row\n"; }
$sth->finish;
$dbh1->disconnect;
'Hope this gives a hint about what you are trying to do.
keep the rudder amid ship and beware the odd typo
RE: Perl / CGI / Mysql
while ($var1,$var2,$var3...) = $sth->fethrow_array)
If you prefer the hash, you could also assigning an alias name to the function results. Check the mysql docs.