Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Perl / CGI / Mysql

Perl / CGI / Mysql

Perl / CGI / Mysql


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


RE: Perl / CGI / Mysql

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";    }

'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

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close