Обсуждение: bytea or large object

Поиск
Список
Период
Сортировка

bytea or large object

От
Jean-Christophe FABRE
Дата:
Hi,

I would like to store .pdf files in a database, which is accessed through a
PHP interface.
which is the best way to store binary data?
- bytea? (with the tricky handling of escape chars)
- large objects?

thanks

JC

PS: I didn't found any example of scripts using bytea in PHP, does someone
has some?


_________________________________________________________
Jean-Christophe FABRE
INRA - UMR Sol & Environnement tel: +33 (0)4 99 61 23 51
2, place Viala fax: +33 (0)4 67 63 26 14
34060 MONTPELLIER cedex 1
FRANCE


Re: bytea or large object

От
Timothy_maguire@hartehanks.com
Дата:
an alternative that I do for situations like this is store the file
location in the db, then when you want to call it, you can generate a link
on the web page from the db pointing to the file.  The file is stored on
the server, not in the db.

Tim.

Timothy P. Maguire
Web Developer II
Harte-Hanks
978 436 3325




              
                      Jean-Christophe FABRE
              
                      <jean-christophe.fabre@ens        To:       pgsql-sql@postgresql.org, pgsql-php@postgresql.org
              
                      am.inra.fr>                       cc:
              
                      Sent by:                          Subject:  bytea or large object
              
                      pgsql-php-owner@postgresql
              
                      .org
              

              

              
                      04/03/2002 09:47 AM
              

              

              





Hi,

I would like to store .pdf files in a database, which is accessed through a
PHP interface.
which is the best way to store binary data?
- bytea? (with the tricky handling of escape chars)
- large objects?

thanks

JC

PS: I didn't found any example of scripts using bytea in PHP, does someone
has some?


_________________________________________________________
Jean-Christophe FABRE
INRA - UMR Sol & Environnement tel: +33 (0)4 99 61 23 51
2, place Viala fax: +33 (0)4 67 63 26 14
34060 MONTPELLIER cedex 1
FRANCE


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org
HARTE- HANKS PRIVILEGED AND CONFIDENTIAL INFORMATION- if you are not the
addressee or authorized to receive this for the addressee, you must not
use, copy, disclose or take any action based on this message or any
information herein and should delete this message.





Re: bytea or large object

От
Joe Conway
Дата:
Jean-Christophe FABRE wrote:
 >
 > Hi,
 >
 > I would like to store .pdf files in a database, which is accessed through
 > a PHP interface. which is the best way to store binary data? -
 > bytea? (with the tricky handling of escape chars) - large objects?
 >
 > thanks
 >
 > JC
 >
 > PS: I didn't found any example of scripts using bytea in PHP, does
someone
 > has some?

Here's an escape script that was sent to me by Thomas T. Thai.

function escByteA($binData) {
  /**
   * \134 = 92 = backslash, \000 = 00 = NULL, \047 = 39 = Single Quote
   *
   * str_replace() replaces the searches array in order. We must
   * process the 'backslash' character first. If we process it last,
   * it'll replace all the escaped backslashes from the other searches
   * that came before.
   */
   $search = array(chr(92), chr(0), chr(39));
   $replace = array('\\\134', '\\\000', '\\\047');
   $binData = str_replace($search, $replace, $binData);
   return $binData;
}

There is also a function built in to PHP 4.1.2, available if you're
using PostgreSQL 7.2, called pg_escape_bytea.

Read the pdf file into a string, then use either of these to escape the
string. The you can do a simple SQL insert. To retrieve the original
files, use stripcslashes() to restore the query result string.

Hope this helps,

Joe



Re: [SQL] bytea or large object

От
Frank Joerdens
Дата:
On Wed, Apr 03, 2002 at 08:12:45AM -0800, Joe Conway wrote:
> Jean-Christophe FABRE wrote:
>  >
>  > Hi,
>  >
>  > I would like to store .pdf files in a database, which is accessed through
>  > a PHP interface. which is the best way to store binary data? -
>  > bytea? (with the tricky handling of escape chars) - large objects?
>  >
>  > thanks
>  >
>  > JC
>  >
>  > PS: I didn't found any example of scripts using bytea in PHP, does
> someone
>  > has some?
>
> Here's an escape script that was sent to me by Thomas T. Thai.
>
> function escByteA($binData) {
>   /**
>    * \134 = 92 = backslash, \000 = 00 = NULL, \047 = 39 = Single Quote
>    *
>    * str_replace() replaces the searches array in order. We must
>    * process the 'backslash' character first. If we process it last,
>    * it'll replace all the escaped backslashes from the other searches
>    * that came before.
>    */
>    $search = array(chr(92), chr(0), chr(39));
>    $replace = array('\\\134', '\\\000', '\\\047');
>    $binData = str_replace($search, $replace, $binData);
>    return $binData;
> }
>
> There is also a function built in to PHP 4.1.2, available if you're
> using PostgreSQL 7.2, called pg_escape_bytea.

AFAIK you need PHP >= 4.2 to use pg_escape_bytea which is currently
available as rc1, i.e. not released. I tried pg_escape_bytea with rc1
and it segfaults (the process crashes). The function above works fine
though.

Regards, Frank

Re: [SQL] bytea or large object

От
Martín Marqués
Дата:
On Jue 04 Abr 2002 04:00, you wrote:
> >
> > There is also a function built in to PHP 4.1.2, available if you're
> > using PostgreSQL 7.2, called pg_escape_bytea.
>
> AFAIK you need PHP >= 4.2 to use pg_escape_bytea which is currently
> available as rc1, i.e. not released. I tried pg_escape_bytea with rc1
> and it segfaults (the process crashes). The function above works fine
> though.

PHP-4.2.0RC2 is out. :-)

--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués                  |        mmarques@unl.edu.ar
Programador, Administrador, DBA |       Centro de Telematica
                       Universidad Nacional
                            del Litoral
-----------------------------------------------------------------