Edit report at http://bugs.php.net/bug.php?id=35800&edit=1
ID: 35800 Comment by: wmoran at potentialtech dot com Reported by: vinny at xs4all dot nl Summary: pg_query_params fails to escape NULL in bytea fields Status: Open Type: Feature/Change Request Package: PostgreSQL related Operating System: winxp sp2 PHP Version: 5.1.1 Block user comment: N Private report: N New Comment: I can confirm this problem on FreeBSD 8.1 with PHP 5.3.5 and PostgreSQL 8.4.6. Note that it is ONLY parametrized queries that exhibit the problem. Proper use of pg_escape_bytea() and pg_unescape_bytea() works as expected. Previous Comments: ------------------------------------------------------------------------ [2006-07-10 14:09:15] burleybutler at hotmail dot com 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. ------------------------------------------------------------------------ [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/bug.php?id=35800&edit=1