store a file in mysql

Discussion in 'Perl Misc' started by joe, Apr 18, 2004.

  1. joe

    joe Guest

    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
     
    joe, Apr 18, 2004
    #1
    1. Advertising

  2. joe wrote:

    > 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
     
    Gregory Toomey, Apr 18, 2004
    #2
    1. Advertising

  3. joe wrote:
    > 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
     
    Gerhard Heift, Apr 18, 2004
    #3
  4. joe

    Guest

    joe <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Apr 19, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JL
    Replies:
    0
    Views:
    1,179
  2. =?Utf-8?B?UnVkeQ==?=

    to store or not to store an image

    =?Utf-8?B?UnVkeQ==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    677
    =?Utf-8?B?UnVkeQ==?=
    Mar 30, 2005
  3. Joshua
    Replies:
    0
    Views:
    586
    Joshua
    Oct 20, 2004
  4. Replies:
    2
    Views:
    6,255
  5. Jeffrey H. Coffield
    Replies:
    1
    Views:
    1,941
Loading...

Share This Page