insert blob

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Natoli

    insert blob

    Having created a table with a longblob column, what is the insert syntax to
    set the value of the longblob column? The data will be read from a file.


  • Norman Peelman

    #2
    Re: insert blob

    "Frank Natoli" <frankn@nospam. com> wrote in message
    news:eRPsd.6582 $Va5.3971@newsr ead3.news.atl.e arthlink.net...[color=blue]
    > Having created a table with a longblob column, what is the insert syntax[/color]
    to[color=blue]
    > set the value of the longblob column? The data will be read from a file.
    >
    >[/color]

    example:

    UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$fil edata')
    WHERE id = 1

    where $filedata is equal to 'drive:/path/to/your/file'


    Norman


    --
    Avatar hosting at www.easyavatar.com


    Comment

    • Frank Natoli

      #3
      Re: insert blob

      Thanks. Will this work if the data in $filedata is binary? Or must I base64
      the data first?

      "Norman Peelman" <npeelman@cfl.r r.com> wrote in message
      news:AN3td.9592 1$8G4.63908@tor nado.tampabay.r r.com...
      "Frank Natoli" <frankn@nospam. com> wrote in message
      news:eRPsd.6582 $Va5.3971@newsr ead3.news.atl.e arthlink.net...[color=blue]
      > Having created a table with a longblob column, what is the insert syntax[/color]
      to[color=blue]
      > set the value of the longblob column? The data will be read from a file.
      >
      >[/color]

      example:

      UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$fil edata')
      WHERE id = 1

      where $filedata is equal to 'drive:/path/to/your/file'


      Norman


      --
      Avatar hosting at www.easyavatar.com



      Comment

      • Norman Peelman

        #4
        Re: insert blob

        If $filedata is a file on your filesystem -> 'c:\\images\\it em_1.jpg' then
        there appears to be no need to do anything. MySQL will load the data as-is.
        If you 'read' $filedata into a variable first via fopen,fread,fcl ose then it
        seems that you must either base64 or addslashes it before MySQL will except
        it. In this case:

        $data = '';
        $fp = fopen($filedata ,'r');
        while (!feof($fp))
        {
        $data .= fread($fp,1024) ;
        }
        fclose($fp);
        $slashed_data = addslashes($dat a);
        UPDATE table_name SET filesize = $filesize, data = '$slashed_data' WHERE id
        = 1
        ---

        notice no LOAD_FILE, and quotes around the variable...


        Norman
        --
        Avatar hosting at www.easyavatar.com
        "Frank Natoli" <franknatoli@wo rldnet.att.net. nospam> wrote in message
        news:KV5td.8695 $714.8086@newsr ead2.news.atl.e arthlink.net...[color=blue]
        > Thanks. Will this work if the data in $filedata is binary? Or must I[/color]
        base64[color=blue]
        > the data first?
        >
        > "Norman Peelman" <npeelman@cfl.r r.com> wrote in message
        > news:AN3td.9592 1$8G4.63908@tor nado.tampabay.r r.com...
        > "Frank Natoli" <frankn@nospam. com> wrote in message
        > news:eRPsd.6582 $Va5.3971@newsr ead3.news.atl.e arthlink.net...[color=green]
        > > Having created a table with a longblob column, what is the insert syntax[/color]
        > to[color=green]
        > > set the value of the longblob column? The data will be read from a file.
        > >
        > >[/color]
        >
        > example:
        >
        > UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$fil edata')
        > WHERE id = 1
        >
        > where $filedata is equal to 'drive:/path/to/your/file'
        >
        >
        > Norman
        >
        >
        > --
        > Avatar hosting at www.easyavatar.com
        >
        >
        >[/color]


        Comment

        Working...