php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53127 pg_escape_bytea returns a format different from the expectation
Submitted: 2010-10-21 13:26 UTC Modified: 2010-10-22 09:07 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: nakamura at nepsys dot ddo dot jp Assigned:
Status: Wont fix Package: PostgreSQL related
PHP Version: 5.3.3 OS: Linux kernel 2.6.27
Private report: No CVE-ID: None
 [2010-10-21 13:26 UTC] nakamura at nepsys dot ddo dot jp
Description:
------------
Using PostgreSQL 9.0.1, pg_escape_bytea function returns new "hex" format.
By defaults, PostgreSQL outputs new "hex" format for bytea data.
It is possible to change to "escape" format by modifying the postgresql.conf file. 

I expecting the test script displays "AAA" always.

However, pg_escape_bytea actually returns a different ("hex") format while the database is connected. 
After disconnected, pg_escape_bytea returns correct ("escape") format.


Test script:
---------------
<?php
$link = pg_connect('dbname=template1 user=postgres');
$version = pg_version($link);
print "PostgreSQL version information\n";
var_dump($version);

$result = pg_query($link,"show bytea_output");
$col = pg_fetch_row($result,0);
pg_free_result($result);
print "environment variable: bytea_output\n";
var_dump($col);


print "pg_escape_bytea('AAA') before database connection closing\n";
print pg_escape_bytea('AAA')."\n";


pg_close($link);
print "pg_escape_bytea('AAA') after database connection closing\n";
print pg_escape_bytea('AAA')."\n";

Expected result:
----------------
PostgreSQL version information
array(3) {
  ["client"]=>
  string(5) "9.0.1"
  ["protocol"]=>
  int(3)
  ["server"]=>
  string(5) "9.0.1"
}
environment variable: bytea_output
array(1) {
  [0]=>
  string(6) "escape"
}
pg_escape_bytea('AAA') before database connection closing
AAA
pg_escape_bytea('AAA') after database connection closing
AAA


Actual result:
--------------
PostgreSQL version information
array(3) {
  ["client"]=>
  string(5) "9.0.1"
  ["protocol"]=>
  int(3)
  ["server"]=>
  string(5) "9.0.1"
}
environment variable: bytea_output
array(1) {
  [0]=>
  string(6) "escape"
}
pg_escape_bytea('AAA') before database connection closing
\\x414141
pg_escape_bytea('AAA') after database connection closing
AAA


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-22 09:07 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2010-10-22 09:07 UTC] aharvey@php.net
There's no way in the PQ API to choose the old escaping behaviour --
which behaviour is used depends on the PostgreSQL server version, if
the connection is active.
 [2011-09-27 04:35 UTC] zlobnynigga at yandex dot ru
I have experienced the same issue with PHP 5.3.5 (PHP 5.3.5-1ubuntu7.2ppa1~lucid with Suhosin-Patch). Under Ubuntu Lucid 2.6.32. But with PHP 5.3.5 under CentOS 2.6.18 there is no such problem. Important thing: both Ubuntu and CentOS hosts are connected to the same PostgreSQL 9.0.3 with 'bytea_output' set to 'escape' (in postgresql.conf). Therefore, I think that which behaviour is used DOES NOT depend on the PostgreSQL server version. It depends on pgsql or pdo_pgsql extensions version (or PHP versions, I have 5.3.5 on both hosts, but they are not the same at least because of some dist specific things). Unfortunately, PHP under ubuntu can not start with pgsql.so from CentOS, so I can't make tests I want. But it looks clear: two different PHPs connect to single PostgreSQL and it results in different behaviour.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC