Khatri has asked for the wisdom of the Perl Monks concerning the following question:

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;

Replies are listed 'Best First'.
Re: insert file into mysql
by chargrill (Parson) on Jan 31, 2006 at 21:28 UTC

    1) Yes.

    2) Look around here: 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
by leocharre (Priest) on Jan 31, 2006 at 22:05 UTC

    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
by Adrade (Pilgrim) on Feb 01, 2006 at 05:04 UTC
    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:
    <form action="http://www.site.com/path/to/script.pl" method=POST ENCTY +PE="multipart/form-data"> Address: <input type="text" name="address"><br> File: <input type="file" name="file"><br> <input type="submit"></form>
    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","passwo +rd"); my $fh = $cgi->upload('file'); my $data; $data .= $_ while <$fh>; my $p = $dbh->prepare("insert into `tablename` (`address`,`data`) valu +es (?,?)"); $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!