|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 18:00:01 2025 UTC |
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!