in reply to Inserting file into a database

I'm not up on Access, but I believe this piece of SQL will just load the filename and the letter 'A' into the table. Do you want to load the contents of the file into the table? As one field in a table? Then you're going to have to read the file contents into a scalar and then insert that into the table:

use strict; my $filename = "File_Name_One"; my $letter = "A"; my $filecontents = ""; open( FH, "<$filename" ) || die "unable to open $filename ($!)\n"; { local( $/ ); undef $/; $filecontents = <FH>; } close( FH ); my $firstvar = $dbh->quote($filecontents); my $secondvar = $dbh->quote($letter); my $statement = "Insert into tableOne (filename, letter) values ($fil +econtents, $letter)";

The usual caveats apply - the contents of the file need to match the definition of the column (large enough, binary vs text, etc).

-derby

Replies are listed 'Best First'.
Re: Re: Inserting file into a database
by Anonymous Monk on Jan 10, 2003 at 13:37 UTC
    Thanks for many responses. I just want to load the filename and the letter in the database not the contents of the file.

    Is the above script going to work? I cant seem to get it to work.
      Okay. For your above script, put some error checking into it so you can see where the failure is taking place.

      #!/usr/bin/perl -w use strict; my $filename = "File_Name_One"; my $letter = "A"; my $dbh = DBI->connect("DBI:ODBC:databasename", "","") || die "error: ($DBI::errstr)\n"; my $firstvar = $dbh->quote($filename); my $secondvar = $dbh->quote($letter); my $statement = "Insert into tableOne (filename, letter) values ($firstname, $letter)"; # Now you need to actually execute the statement $dbh->do( $statment ) || die "error: $dbh->errstr\n"; # rest of code

      -derby

        Thank yous to all.