develooper Front page | perl.beginners | Postings from March 2002

perl DBI to Mysql , what happens when field I query is blank ?

Thread Next
From:
FLAHERTY, JIM-CONT
Date:
March 20, 2002 07:56
Subject:
perl DBI to Mysql , what happens when field I query is blank ?
Message ID:
6D0317C617A8D3119EC000A0C9FC45240190AA19@kinx68322m1.cnet.navy.Mil
Hello I have redhat 7.1 and mysql  , I am trying to query DB of People
if there is no record for this person , I want to add them . My problem
seams to be what is in query results with it comes back blank
 
here is the code 
 
 

$dbh1 =DBI ->connect($data_source, $username, $password) or die "cant
connect to
 $data_source : my $dbh-> errstr\n";
my $sth1 = $dbh1 -> prepare("select owner from users where owner =
'$user_n'");
$sth1 -> execute or die " unable to execute query ";
 
# $sth1 -> finish;
# $dbh1->disconnect;
 
my $array_ref = $sth1 -> fetchall_arrayref();
 
  foreach $row(@$array_ref){
 

my($owner) = @$row;
 
  if($owner eq NULL){ 

 
$dbh4 =DBI ->connect($data_source, $username, $password) or die "cant
connect to
 $data_source : my $dbh-> errstr\n";
 
my $sth2 = $dbh4 -> prepare("insert into users(owner)values('$user_n')");
$sth2 -> execute or die " unable to execute query ";
 
    }
 

}
 

$sth -> finish;
 
#  look up results ??
 
 
 
 
 
thanks in advance
Jim
 
 
 
 
 

 
 
 
 
 

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About