|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35338 PDO freezes while retreiving binary data from postgres
Submitted: 2005-11-22 20:57 UTC Modified: 2005-11-26 18:28 UTC
From: f dot engelhardt at 21torr dot com Assigned: wez (profile)
Status: Not a bug Package: PDO related
PHP Version: 5CVS-2005-11-22 (CVS) OS: Linux
Private report: No CVE-ID: None
 [2005-11-22 20:57 UTC] f dot engelhardt at 21torr dot com
I tried to write binary data into a postgresql table, that work, but i can not get this data out the table anymore.

Reproduce code:

$dbh = new PDO('pgsql:host=localhost;dbname=test','root','fo0224');

$q = 'SELECT data FROM foobar';
$stmt = $dbh->prepare($q);
if ($stmt) 
  if (!$stmt->execute())
  if (!$stmt->fetch(PDO::FETCH_BOUND))
  header('Content-Type: image/jpeg');
  echo $sData;
} else {


Table foobar only has a bytea column named data

Expected result:
should display the image

Actual result:
the php-process does not do anything, the browser waits for an answer (i waited 5 minutes, but nothing happened)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-22 22:36 UTC]
Are you able to reproduce it with something different than PgSQL? Sqlite, for example?
Are you able to reproduce it with PHP CLI?

 [2005-11-23 12:25 UTC] f dot engelhardt at 21torr dot com
Exact the same script (replacing pgsql by mysql in the new PDO line) it works with mysql.
I also tried it with CLI, the same error.

And i found out another bug. I tried to insert data into the table with pdo into a postgresql database, but there are only some bytes inserted, not all.



$dbh = new PDO('pgsql:host=localhost;dbname=test','root','fo0224');

$sData = file_get_contents('/home/bowman/.fluxbox/backgrounds/NVA-91.jpg');

$q = 'INSERT INTO foobar (data) VALUES (:data)';
$stmt = $dbh->prepare($q);
if ($stmt) 
  if (!$stmt->execute())
  //header('Content-Type: image/jpeg');
  echo $sData;
} else {


This script is working with MySQL, but not with Postgresql
 [2005-11-23 12:28 UTC] f dot engelhardt at 21torr dot com
Sorry, i forgot to give you another hint:
The data in the postgresql database in the first script was added with the pg_-functions into a bytea field.
As explained some minutes ago, inserting binary data into a bytea field in postgres via pdo failes with no error output.
Maybe i am using the wrong datatype for binary data in postgres, but i only found bytea for binary puroses.
 [2005-11-23 13:53 UTC]
Assigned to the maintainer.
 [2005-11-25 04:38 UTC]
Please try using this CVS snapshot:
For Windows:

I've made some adjustments in CVS; please try the next PHP 5.1 snapshot and let me know how it goes.
 [2005-11-25 11:05 UTC] f dot engelhardt at 21torr dot com
I am sorry, but i have to tell you, that nothing changed.
After executing the insert script, there was only the following in the database:
id 	data
4	\377\330\377\340

There has to more data.
I know, that when using the pg_ functions i have to pg_escape_bytea() function on the binary data, and when i
read it, i have to use the pg_unescape_bytea() function.
Maybe this isn?t done.
 [2005-11-25 11:12 UTC] f dot engelhardt at 21torr dot com
It works, if i specify PDO::PARAM_LOB with the bindParam() call in the insert script:


I am not sure, if it should work without this, but it is working on postgresql if i do it like this.
It also works with mysql, but that was working also without the PDO::PARAM_LOB parameter.

So my question is:
Is it desired that binary data can be inserted into a table without PDO::PARAM_LOB or not?
 [2005-11-26 18:28 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

When using binary data you must specify the param as LOB via PDO::PARAM_LOB. This is necessary to allow the underlying layer to realize the data is binary and use a binary escaping function, rather then a string escaping function. In PostgreSQL using a string escaping function or binary data results in data loss.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 07:01:30 2024 UTC