Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Impossible to retrieve BLOB from DB with PostgreSQL >= 9.0

The new default 'hex' for bytea_output setting, causes PHP to
incorrectly process the column's contents. As recommended in [1], we set
bytea_output to 'escape' when connecting, to ensure this works

Fixes #4

[1] https://bugs.php.net/bug.php?id=59831
  • Loading branch information...
commit f94bf9f68217976e5f37ab6ec5b45c02740670b4 1 parent db33f7b
@dregad dregad authored
Showing with 10 additions and 0 deletions.
  1. +1 −0  docs/docs-adodb.htm
  2. +9 −0 drivers/adodb-postgres64.inc.php
View
1  docs/docs-adodb.htm
@@ -6192,6 +6192,7 @@
</ul>
<p>mysql/mysqli: Fix ability for MetaTables to filter by table name, broken since 5.15. See http://phplens.com/lens/lensforum/msgs.php?id=19359
<p>sybase: Removed redundant sybase_connect() call in _connect(). See Github #3
+<p>pgsql: Fix output of BLOB (bytea) columns with PostgreSQL >= 9.0
<p><a name=5.18><b>5.18 3 Sep 2012</b>
<p>datadict-postgres: Fixes bug in ALTER COL. See http://phplens.com/lens/lensforum/msgs.php?id=19202. Also fixed bugs in MetaType() checking $fieldobj properties.
View
9 drivers/adodb-postgres64.inc.php
@@ -711,6 +711,15 @@ function _connect($str,$user='',$pwd='',$db='',$ctype=0)
if ($this->pgVersion >= 7.1) { // good till version 999
$this->_nestedSQL = true;
}
+
+ # PostgreSQL 9.0 changed the default output for bytea from 'escape' to 'hex'
+ # PHP does not handle 'hex' properly ('x74657374' is returned as 't657374')
+ # https://bugs.php.net/bug.php?id=59831 states this is in fact not a bug,
+ # so we manually set bytea_output
+ if (version_compare($info['version'], '9.0', '>=')) {
+ $this->Execute('set bytea_output=escape');
+ }
+
return true;
}
Please sign in to comment.
Something went wrong with that request. Please try again.