I have run into this problem before, but unfortunately, I can't seem
to figure out what I am doing wrong again this time...  I am working on a
script to parse a data file and INSERT/UPDATE this data into a MySQL
database table.  I am able to verify that the data I am dealing with is what
I expect, and the simple logic in the script is performing as desired.  The
problem I am running into at the moment is the following pair of error
messages:

DBD::mysql::st execute failed: You have an error in your SQL syntax near
'key ='
1281-02F'' at line 1 at ./emc_data2.pl line 35, <FILE> line 134.
DBD::mysql::st fetch failed: fetch() without execute() at ./emc_data2.pl
line 36
, <FILE> line 134.

        Here is the pertinent section of script:

opendir(DATA, "$file_source");
while ($file = readdir(DATA)) {
  if ($file =~ /^emc/) {
    print "Processing $file. \n";
    open(FILE, "$file_source$file");
    ($x, $host) = split(/./, $file);
    while ($data = <FILE>) {
      @fields = split(/\s+/, $data);      
      my $chk = $dbh->prepare("SELECT * FROM emc_usage WHERE key
='$fields[5]'");
      $chk->execute ();
      my $test = $chk->fetch ();
      if ($test[8]) {
        $used = "Yes";
      } else {
        $used = "No";
      }
      my $cnt = $chk->rows;
      if ($cnt == 0) {
        
        my $insert = $dbh->prepare("INSERT INTO emc_usage (key, emc_id,
size, prot, host, initial, vg, ctd_num1, used1)
                     VALUES
('$fields[5]','$fields[0]','$fields[2]','$fields[4]','$host',NOW,'$fields[6]
','$ctd','$used')")
                     or print "Error adding entry to database: ",
$dbh->errstr, "\n";
        
      }
    }
    close(FILE);
  }
}
closedir(DATA);

        Thanks in advance for the help.  I am sure the answers will most
likely generate more questions, but hopefully this is a start.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com


Reply via email to