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>
Copyright © 1994 - 2019 Linux Journal. All rights reserved.