On 6/12/07, Northstardomus <[EMAIL PROTECTED]> wrote:
snip
        $dbh->prepare('INSERT INTO area_status (areaID, survey_date,
update_time, status ) VALUES (?,?,?,?)');
        $dbh->execute('$values[0]', '$values[1]', '$values[2]',
'$values[3]');
snip

You are getting an error because $dbh->prepare returns a statement
handle that can be executed.  The code should be written like this:

my $sth = $dbh->prepare('
   INSERT INTO area_status (areaID, survey_date, update_time, status )
       VALUES (?,?,?,?)
');
$sth->execute(@values[0 .. 3]);

Also, connecting to the database every time you want to do something
is expensive.  You should connect once near the beginning of the
script and use that connection for the rest of the script.  The
statement handle may also be reused, so you might want to name it with
a better name than $sth* like this:

my $dbh = DBI->connect(...);

my $insert_area_status_sth = $dbh->prepare(...);

while (<DATA>) {
   my @rec = split /,/;
   $insert_area_status_sth->execute(@rec) if $rec[0] eq 'Y';
}


* for handles that have a limited scope $sth is perfectly fine

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to