store a file in mysql

J

joe

hi i am trying to save a file in store in a $buff into a mysql database
this does not work. I found the execute_query in an example but i guess
that function is not part of dbi.

$dbhi = DBI->connect("DBI:mysql:mymail",root,freebsd);
my $sql8="insert into imgarchief(image)values('$buf')";
## my $sth8=Execute_Query($sql8);
my $roows8=$dbhi->do($sql8) || die "Error";

$dbhi->disconnect;

thanks
 
G

Gregory Toomey

joe said:
my $sql8="insert into imgarchief(image)values('$buf')";

When $buf gets expanded here, the statement will look like gobbldygook.

You will either need to use the mysql hex/unhex functions, or define a dbi
variable (not sure of the right terminology).


gtoomey
 
G

Gerhard Heift

joe said:
hi i am trying to save a file in store in a $buff into a mysql database
this does not work. I found the execute_query in an example but i guess
that function is not part of dbi.

$dbhi = DBI->connect("DBI:mysql:mymail",root,freebsd);
my $sql8="insert into imgarchief(image)values('$buf')";
## my $sth8=Execute_Query($sql8);
my $roows8=$dbhi->do($sql8) || die "Error";

$dbhi->disconnect;

thanks

# Making Connection
my $dbhi = DBI->connect("DBI:mysql:mymail",root,freebsd);

# Prepare the SQL-Statement
my $sql8 = "insert into imgarchief (image) values(?)";
my $sql = $dbhi->prepare($sql8);

# Execute it with the Buffer
$sql->execute($buf)

$dbhi->disconnect;

see man DBI

Gerhard
 
C

ctcgag

joe said:
hi i am trying to save a file in store in a $buff into a mysql database
this does not work. I found the execute_query in an example but i guess
that function is not part of dbi.

Did you look in the documentation for DBI? execute_query is not there (in
modern versions anyway, I don't know it may have been there before and
removed), you don't have to guess. Maybe it was a user-defined sub defined
in the example you saw it in.
$dbhi = DBI->connect("DBI:mysql:mymail",root,freebsd);
my $sql8="insert into imgarchief(image)values('$buf')";

use bind variables. "...values(?)"
## my $sth8=Execute_Query($sql8);

Execute_Query is not the same thing as execute_query.
my $roows8=$dbhi->do($sql8) || die "Error";

$dbhi->do($sql8,undef,$buf);

I tend to use RaiseError when I connect, thus I don't have to check each
time.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top