pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vincent de Phily <vdephily@bluemetrix.com>
To: pgsql-php@postgresql.org
Subject: Re: pg_[un]escape_bytea, pgsql 8.2.1, php 5.1.6, Linux
Date: Thu, 8 Feb 2007 12:12:43 +0000
Message-ID: <200702081212.43200.vdephily@bluemetrix.com> (raw)
In-Reply-To: <eqe0n8$1ohp$1@news.hub.org>
References: <302670f20702011827x28d9a689m388b2c8a703f31af@mail.gmail.com>
	<302670f20702070658vb0913e2xa51d153ddbe5b34d@mail.gmail.com>
	<eqe0n8$1ohp$1@news.hub.org>

On Thursday 08 February 2007, ljb wrote:
> gwchamb@gmail.com wrote:
> > Vincent...
> >
> >> This would be a problem related to php, not postgres. I'm handling
> >> binary data in parameterized and COPY queries just fine with c++.
> >
> > I'm not ruling-out PHP, but I've seen claims of pg_[un]escape_bytea
> > being only wrappers to the Pg functions.
>
> That is correct, the PHP function relies on the PostgreSQL library to do
> the work. But the problem of using a parameterized query with bytea data
> is specific to PHP. PostgreSQL allows you to either escape the bytea
> data for use as a text-mode parameter, or pass it 'raw' as a binary-mode
> parameter. I don't know a good way to do the first in PHP, and the PHP
> PostgreSQL interface doesn't support the second at all.

This sparked my interest, so I checked the libpq docs 
(http://www.postgresql.org/docs/8.2/interactive/libpq-exec.html) and wrote 
some php tests.

The postgres doc say that the escape functions should only be used "for 
Inclusion in SQL Commands", and that "it is not necessary nor correct to do 
escaping when a data value is passed as a separate parameter in 
PQexecParams".
But when I try to pass the raw data using pg_query_params(), postgres 
complains about UTF8 (on a supposedly bytea field). Makes you wonder which 
postgres function does pg_query_params() really wrap around...

I reallize I went all this way to just re-discover what has been said in this 
thread, but if I needed the extra research, maybe other will find it 
insightfull.
-- 
Vincent de Phily



view thread (10+ messages)  latest in thread

Message-ID: <200702081212.43200.vdephily@bluemetrix.com>
Permalink:  ../200702081212.43200.vdephily@bluemetrix.com/
Also on:    postgresql.org/message-id/200702081212.43200.vdephily@bluemetrix.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: vdephily@bluemetrix.com
  Subject: Re: pg_[un]escape_bytea, pgsql 8.2.1, php 5.1.6, Linux
  In-Reply-To: <200702081212.43200.vdephily@bluemetrix.com>
  References: <302670f20702011827x28d9a689m388b2c8a703f31af@mail.gmail.com> <302670f20702070658vb0913e2xa51d153ddbe5b34d@mail.gmail.com> <eqe0n8$1ohp$1@news.hub.org> <200702081212.43200.vdephily@bluemetrix.com>

* 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