insert file into mysql
Khatri
created: 2006-01-31 16:20:41
On web page, when I submit I'm taking address of the file that I want to store and when I come on the next page it will store that file into data base. Question 1) can we do same thing using single page Question 2) how can we store file in mysql using perl Thanks
$perl =~ s/$difficult/$easy/g;
Re: insert file into mysql
created: 2006-01-31 16:28:11

1) yes.

2) look around here: [cpan://mysql]



--chargrill
$/  =  q#(\w)#  ;  sub  sig { print scalar reverse  join  ' ',  @_  }  sig
map { s$\$/\$/$\$2\$1$g && $_ } split( ' ', ",erckha rlPe erthnoa stJu" );
Re: insert file into mysql
created: 2006-01-31 17:05:31

this one page two page thing is confusing,
is this a file upload ?
taking address? what the h*ll are you talking about ?! :-)

mysql stuffs... perl is really sexy with db stuff.. here's a rough example.. (i said rough!)..

use DBI;

my $CONECTION = DBI->connect("DBI:mysql:database=$databasename; host=$hostname", "$username", "$password", { RaiseError=>1, AutoCommit=>1}) or die $DBI::errstr ;

my $insert = $CONNECTION->prepare("INSERT INTO yourtable (col1, col2, col3) values (?,?,?)");

# if you are gonna be executing the same thing more then once, 
# you want to 'prepare' it and then execute it as needed, 
# you dont wanna prepare and execute the same thing over
# an over again, depends on your load..

$insert->execute('val1','val2','val3');

$insert->finish;

$CONNECTION->disconnect;
Re: insert file into mysql
created: 2006-02-01 00:04:08
I think you're looking to collect a piece of textual information in addition to binary data from a file. The first thing you're gonna need to be sure of is that your table is setup correctly. Presumably, you're going to need a sort of TEXT field for the address, and you're gonna need a BLOB for the binary data.

The HTML is gonna need to be setup something like this:
Address:
File:
The Perl code is going to probably be something like this:
#!/usr/bin/perl

use strict;
use CGI;
use DBI;

my $cgi = new CGI;
my $dbh = DBI->connect("DBI:mysql:dbname:localhost","username","password");
my $fh = $cgi->upload('file');

my $data;
$data .= $_ while <$fh>;

my $p = $dbh->prepare("insert into `tablename` (`address`,`data`) values (?,?)");
$p->execute($cgi->param('address'), $data);
$p->finish;

$dbh->disconnect;
Although this is rather basic (and untested!!), I hope it leads to an eventual solution to your problem, of course, assuming that I am understanding it correctly :-).

Best, and good luck!
  -Adam

--
By a scallop's forelocks!

perlmonks.org content © perlmonks.org and Adrade, chargrill, Khatri, leocharre

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03