Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl / CGI / Mysql

Status
Not open for further replies.

ogri

Programmer
Sep 26, 2000
74
GB
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
 
presumably, your function returns rows. Also, assuming you are using DBI/DBD..... I am more familiar with DBI/DBD::pg for PostgreSQL, but, I think it will be the same...

$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
 
You can also use:

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top