ID:               35800
 Comment by:       burleybutler at hotmail dot com
 Reported By:      vinny at xs4all dot nl
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: winxp sp2
 PHP Version:      5.1.1
 New Comment:

I too found using a parameter doesn't work for uploading bytea binary
data - either unescaped (zero bytes got saved) or using pg_escape_bytea
(too many bytes got saved). Was hoping it would get around the
memory/speed problems with pg_escape_bytea for large chunks of data.


Previous Comments:
------------------------------------------------------------------------

[2005-12-25 16:51:31] vinny at xs4all dot nl

There is no need to get rude with your 'RTFM'. I just forgot to put
'array()' around the parameter when I typed it in the report, that is
all. It stands to reason that if I didn't pass an array I'd get an
error and there would be no record inserted at all. My report clearly
states that it does create a record so that cannot be the problem,
hence I must have made a typo.

Anyway, getting back to the bug; ofcourse there is pg_escape_bytea(), I
already told you that in the original report wich you apparently didn't
bother to read at all. The whole point of pg_query_params is that it
does the escaping for you. Perhaps you'd care to RTM yourself. The bug,
then, is that it apparently doesn't escape bytea data properly; it stops
at the first zero-byte it encounters, making the function unsafe to
use.

I hope this makes things a bit more clear to you and perhaps you might
consider reading the whole report next time. There is no point
reporting bugs if the bugfixers don't even bother to even read them.

------------------------------------------------------------------------

[2005-12-25 16:15:15] [EMAIL PROTECTED]

RTFM: pg_query_params() expects the last parameter to be an array(),
also, there's pg_escape_bytea() function which you can use too.

------------------------------------------------------------------------

[2005-12-25 12:53:00] vinny at xs4all dot nl

Description:
------------
pg_query_params() stops processing binary 'bytea' field data at hex
'00'.



Reproduce code:
---------------
<?php
/**
create a PostgreSQL database (I used 8.1) with a table that has a
'bytea' field. Use pg_query_params to insert binary data from a JPG
image into the bytea field, something like:
*/

pg_query_params("INSERT INTO tabel (byteafield) values ($1)",
file_get_contents('file.jpg'));
?>



Expected result:
----------------
The image should be stored in the database completely.

Actual result:
--------------
Only the first four bytes of the JPG data make it into the database.

JPG data starts with: hex FF D8 FF E0 00 10 4A 46 49
Apparently pg_query_params stops processing the content at '00' which I
guess is because PHP thinks it is at 'EOF'.

If you insert the data with a normal pg_query call and using
pg_escape_bytea() on the JPG data then everything works just fine and
the image is stored properly.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35800&edit=1

Reply via email to