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

How Do I add a record to a table if it dont exist ??

From:
FLAHERTY, JIM-CONT
Date:
March 27, 2002 08:23
Subject:
How Do I add a record to a table if it dont exist ??
Message ID:
6D0317C617A8D3119EC000A0C9FC45240190AA55@kinx68322m1.cnet.navy.Mil
I have a delima I want to add records to a table in mysql , only if that
record isnt there , Help 
 
 
Code 
 
my $sth1 = $dbh -> prepare("select distinct testname from testhistory");
$sth1 -> execute or die " unable to execute query ";
#$sth1 -> finish;
 
my $array_ref1 = $sth1->fetchall_arrayref();
 

  foreach $row(@$array_ref1) {
     my($tname) = @$row;
 

    my $sth5 = $dbh-> prepare("select testname from phistory");
    $sth5 -> execute or die " unable to execute query ";
    #$sth1 -> finish;
 
     my $array_ref5 = $sth5->fetchall_arrayref();
        foreach $row1(@$array_ref5) {
           my($tname) = @$row1;
 
    if ($tname ne ""){
 my $sth2 = $dbh -> prepare("insert into
phistory(testname)values('$tname')");
$sth2 -> execute or die " unable to execute query ";
#$sth1 -> finish;
 
}
 
}
 
 
this code doesnt add at all 
Thanks 
Jim



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