CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI: Re: [brosskgm] Perl MySQL help with code.: Edit Log



FishMonger
Veteran / Moderator

Feb 27, 2013, 8:23 AM


Views: 4522
Re: [brosskgm] Perl MySQL help with code.

Please post your updated script so we can get a better idea of what changes you made.

If I were writing this script, I'd use a hash ref for the returned db data.

example:

Code
# db related vars 
my $host = "remote_host";
my $database = "dbase";
my $tablename = "tname";
my $user = "user";
my $pw = "pw";

my $dbh = DBI->connect("DBI:mysql:$database:$host", $user, $pw,
{RaiseError => 1})
or die "Connection Error: $DBI::errstr\n";

my $sql = "SELECT subscr_id, username FROM $tablename WHERE subscr_id = ?";
my $sth = $dbh->prepare($sql);
$sth->execute($id);
my $subscriber = $sth->fetchrow_hashref;

$sth->finish();


$subscriber would be a hash reference with a structure of:


Code
$subscriber = { 
subscr_id => '1-YS25UHRN3N9D',
username => 'user-email-address'
}



(This post was edited by FishMonger on Feb 27, 2013, 8:26 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Feb 27, 2013, 8:26 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives