pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frank Joerdens <frank@joerdens.de>
To: Joe Conway <mail@joeconway.com>
Cc: Jean-Christophe FABRE <jean-christophe.fabre@ensam.inra.fr>
Cc: pgsql-php@postgresql.org
Subject: Re: [SQL] bytea or large object
Date: Thu, 4 Apr 2002 09:00:01 +0200
Message-ID: <20020404090001.A28086@superfly.archi-me-des.de> (raw)
In-Reply-To: <3CAB29FD.90606@joeconway.com>
References: <5.0.0.25.0.20020403164135.00ad0380@ensam.inra.fr>
	<3CAB29FD.90606@joeconway.com>

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



view thread (7+ messages)  latest in thread

Message-ID: <20020404090001.A28086@superfly.archi-me-des.de>
Permalink:  ../20020404090001.A28086@superfly.archi-me-des.de/
Also on:    postgresql.org/message-id/20020404090001.A28086@superfly.archi-me-des.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: frank@joerdens.de, mail@joeconway.com, jean-christophe.fabre@ensam.inra.fr, pgsql-php@postgresql.org
  Subject: Re: [SQL] bytea or large object
  In-Reply-To: <20020404090001.A28086@superfly.archi-me-des.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox