You need to get the information out with a custom sql statement and put it in some kind of data structure if it exists. There are a lot of ways to do this. a quick example.
#!/usr/bin/perl -w use strict; use DBI; #db connect my $driver = 'mysql'; my $database = 'usersdb'; my $dsn = "DBI:$driver:database=$database"; my $dbh = DBI->connect($dsn, undef, undef); my $user ="bob"; my $user_test = user_exists($user); if (defined $user_test){ print "user $user is already in our database"; }else{ #code to insert user } $dbh->disconnect; sub user_exists{ my $id_val = shift; my $statement = "select user_id from users where user_id = $id_val +"; my $ary_ref = $dbh->selectall_arrayref($statement); if (defined $ary_ref->[0]->[0]){ return $ary_ref->[0]->[0]; }else{ return undef; } }
In reply to Re: mySQL with Perl
by thunders
in thread mySQL with Perl
by skirrow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |