pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PHP pg_escape_string
2+ messages / 2 participants
[nested] [flat]

* PHP pg_escape_string
@ 2009-06-15 08:14  Zdravko Balorda <zdravko.balorda@siix.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Zdravko Balorda @ 2009-06-15 08:14 UTC (permalink / raw)
  To: pgsql-sql



Hi,
I have a PHP/PGSQL question:
there are both pg_(un)escape_bytea() functions
but only one pg_escape_string()... I wonder if I may be
missing something here?

Thank you for any explanation, Zdravko.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: PHP pg_escape_string
@ 2009-06-15 16:10  Andy Shellam <andy-lists@networkmail.eu>
  parent: Zdravko Balorda <zdravko.balorda@siix.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Andy Shellam @ 2009-06-15 16:10 UTC (permalink / raw)
  To: Zdravko Balorda <zdravko.balorda@siix.com>; +Cc: pgsql-sql

Hi,

Zdravko Balorda wrote:
> there are both pg_(un)escape_bytea() functions
> but only one pg_escape_string()... I wonder if I may be
> missing something here?

Yeah, I think you are.  pg_escape_string (funnily enough) escapes string 
data which is then stored in the database.  You would use this for 
escaping things like apostrophes in a text field so PostgreSQL wouldn't 
think the apostrophe in the field is the "end of data" marker.  However 
this string is *not* stored in the database in an escaped form, as it's 
only escaped for the SQL command, therefore it makes no sense to 
unescape it.

bytea columns on the other hand, are a way of sending and receiving 
binary data as a textual representation to/from the database server.  
The data you send and receive is both encoded, therefore you need to 
unescape it to read it back out.  For example a null byte (byte value 0) 
cannot be sent or received in a SQL command, because a null byte 
represents an end-of-string in C.  Other byte values similarly cannot be 
sent in a string because they cannot be converted to a character (e.g. 
ASCII newline/linefeed.)

Regards,
Andy



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2009-06-15 16:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-06-15 08:14 PHP pg_escape_string Zdravko Balorda <zdravko.balorda@siix.com>
2009-06-15 16:10 ` Andy Shellam <andy-lists@networkmail.eu>

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