I'm not sure if I'm using this correctly.
For the following piece of code:
$id = $query->insertid
[What it does: If you have a field that is auto incremented, then this function will come in handy. It will return to you the the unique id given to the field after the query.]
I have two tables that I want to insert into, one table will generate the autonumber that should be pulled by the code above, and the other table will insert that into it's database to link the two databases.
My code:
The error that I get through PERL:
It inserts the first record into the first table just fine, but everything after that does not work. Does anyone have any idea what I may be doing wrong?
Thanks for your time, and looking.
-T
For the following piece of code:
$id = $query->insertid
[What it does: If you have a field that is auto incremented, then this function will come in handy. It will return to you the the unique id given to the field after the query.]
I have two tables that I want to insert into, one table will generate the autonumber that should be pulled by the code above, and the other table will insert that into it's database to link the two databases.
My code:
Code:
use DBI;
$dbh = DBI->connect('dbi:mysql:databases','login','pw');
open (INFILE, "marinedata.txt");
while (<INFILE>) {
$line = $_;
chomp($line);
($sampnum, $multipanel, $date, $location, $foundid, $locationid, $vessel, $sitename, $rest) = split(/\t/, $line, 9);
($month, $day, $year) = split(/\//, $date, 3);
$date2 = $year."-".$month."-".$day;
$query1 = "INSERT INTO tblNetClass (SampleNum, Multipanel, Date, NetLocation, FoundID, LocationID, Vessel, SiteName)
VALUES ('$sampnum', '$multipanel', '$date2', '$location', '$foundid', '$locationid', '$vessel', '$sitename')";
$sth = $dbh->prepare($query1);
$sth->execute ||
die "Could not execute SQL statement!";
$netclassid = $query1->NetClassID;
($subsamp, $stretch, $twine, $twist, $strands, $floats, $rope, $weight, $rdia1, $rlmn1, $rlmx1, $rdia2, $rlmn2, $rlmx2, $rdia3, $rlmn3, $rlmx3, $trimedge, $foul, $breaks, $picid, $initial, $initiald, $classid, $otherid, $constrid, $color, $nettype, $trimclr, $comment) = split(/\t/, $rest, 30);
($month, $day, $year) = split(/\//, $initiald, 3);
$date4 = $year."-".$month."-".$day;
$query2 = "INSERT INTO tblNetDesc (SubSample, StretchMeshSize, TwineDiam, Twist, NumStrands, Floats,
Rope, Weight, RopeDiam1, RopeLngth1min, RopeLngth1max, RopeDiam2,
RopeLngth2min, RopeLngth2max, RopeDiam3, RopeLngth3min, RopeLngth3max,
TrimmedEdge, Foul, BreaksEasily, PictureName, Initial, InitialDate, NetClassID,
ConstructionID, ColorID, NetTypeID, TrimColorID, Comment)
VALUES ('$subsamp', '$stretch', '$twine', '$twist', '$strands', '$floats', '$rope', '$weight',
'$rdia1', '$rlmn1', '$rlmx1', '$rdia2', '$rlmn2', '$rlmx2',
'$rdia3', '$rlmn3', '$rlmx3', '$trimedge', '$foul', '$breaks', '$picid', '$initial',
'$date4', '$netclassid', '$constrid', '$colorid', '$nettype', '$trimclr', '$comment')";
$sth2 = $dbh->prepare($query2);
$sth2->execute ||
die "Could not execute SQL statement!";
}
The error that I get through PERL:
Code:
Can't locate object method "NetClassID" via package "INSERT INTO tblNetClass (SampleNum, Multipanel, Date, NetLocation, FoundID, LocationID,
iteName)
VALUES ('1.01', '4', '2003-5-20', 'Pearl & Hermes Atoll', '1', '3', 'OF', 'MAZE')" (perhaps you forgot to load "INSERT INTO
s (SampleNum, Multipanel, Date, NetLocation, FoundID, LocationID, Vessel, SiteName)
VALUES ('1.01', '4', '2003-5-20', 'Pearl & Hermes Atoll', '1', '3', 'OF', 'MAZE')"?) at dbconn.pl line 55, <INFILE> line 1.
Thanks for your time, and looking.
-T