return to first page linux journal archive
keywordscontents
4143l5

Listing 5: get-user-info.comp

%# -*- mmm-classes: mason -*-
<%perl>
# Make sure that we got a $user_id
return undef unless $user_id;

# Prepare the SQL query
$sth = $dbh->prepare($sql) || die qq{Cannot prepare: "$sql"};

# Execute the query, with the user_id that we were passed
$result = $sth->execute($user_id) || die qq{Cannot execute: "$sql"};

my $row_hashref = $sth->fetchrow_hashref;
return $row_hashref;
</%perl><\n>

<%once>
my $sql = "SELECT username, email, password ";
 $sql .= "FROM Users ";
 $sql .= "WHERE user_id = ? ";

my ($dbh, $sth, $result);
</%once>

<%init>
$dbh = $m->comp("database-connect.comp");
</%init>

<%args>
$user_id => undef
</%args>