php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39341 pg_fetch_assoc returns escaped data
Submitted: 2006-11-02 05:20 UTC Modified: 2007-07-19 01:00 UTC
From: jasen at treshna dot com Assigned: yohgaki (profile)
Status: No Feedback Package: PostgreSQL related
PHP Version: 4.4.4 OS: debian linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jasen at treshna dot com
New email:
PHP Version: OS:

 

 [2006-11-02 05:20 UTC] jasen at treshna dot com
Description:
------------
I have a postgresql database table with a bytea field

 I insert into a record into this table using pg_insert

but when I extract the data using pg_fetch_assoc the binary data is still escaped and needs to be unescaped using pg_unescape_bytea



Reproduce code:
---------------
$db=pg_connect('dbname=foo');
$res=pg_query("select * from images limit 1");
$row=pg_fetch_assoc($res);
header("content-type: $row[type]");
echo /*pg_unescape_bytea(*/$row['data']); 
/* unescape is needed - is this a bug in php? */


Expected result:
----------------
I would expect my binary image to display in the browser

Actual result:
--------------
the browser complains about corruption in the image 
closer examination reveals that the data is still escaped.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-09 05:56 UTC] jasen at treshna dot com
new example code:
I reallise that pg_insert is experimental, but it _seems_ to be working perfectly.

Reproduce code:
---------------
<? 
$data="/'/'\"\001\002\003\004";   # sample data to test with
# you may need to use a different database...
$db=pg_connect('dbname=template1');
if (!$db) die( "couldn't connect to database") ;
if (!pg_query("CREATE TEMPORARY TABLE mytab ( a BYTEA ) ; "))
  die( "couldn't create table\n") ;
if (!pg_insert($db, 'mytab',array(a=> $data )))
  die( "couldn't insert data\n") ;
$res=pg_query("SELECT a FROM mytab");
if (!$res) die( "query failed\n") ;
$row=pg_fetch_assoc($res);
if ($row['a']  ==  $data )
  echo "Retrieved data matched inserted -GOOD!\n";
elseif (pg_unescape_bytea($row['a'])  ==  $data)
  echo "Retrieved data matched escaped version of inserted data - oops!\n";
else
  echo "Retrieved and insterted data differ :(\n";
?>



Expected result:
----------------
Retrieved data matched inserted -GOOD


Actual result:
-------------------
Retrieved data matched escaped version of inserted data - oops!
 [2007-07-19 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-01-22 15:21 UTC] maciej dot pijanka at gmail dot com
testcase show oops here too 

PHP 5.2.5 (cli) (built: Dec 10 2007 13:29:50) 
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 12:01:29 2024 UTC