ID: 45964 Updated by: [EMAIL PROTECTED] Reported By: skrald at amossen dot dk Status: Open Bug Type: PostgreSQL related Operating System: Linux PHP Version: 5.2.6 New Comment:
Well, actually the result isn't reversed to original state. Anyway it seems an expected behavior. <?php $data = "\0\t"; $esc = pg_escape_bytea($data); $unesc = pg_unescape_bytea($esc); var_dump($esc, $unesc); ?> Output: string(10) "\\000\\011" string(8) "\000\011" Nevertheless, says the documentation: "This conversion is not exactly the inverse of PQescapeBytea, because the string is not expected to be "escaped" when received from PQgetvalue. In particular this means there is no need for string quoting considerations, and so no need for a PGconn parameter." And about the two backslashes: "Certain byte values must be escaped (but all byte values can be escaped) when used as part of a bytea literal in an SQL statement. In general, to escape a byte, it is converted into the three digit octal number equal to the octet value, and preceded by usually two backslashes." Previous Comments: ------------------------------------------------------------------------ [2008-09-01 13:10:19] skrald at amossen dot dk Description: ------------ Calling pg_unescape_bytea() on some data that has been escaped with pg_escape_bytea() does not produce the original data as expected. That is: the "unescape" method is not the opposite of the "escape" method. Reproduce code: --------------- <?php $data = file_get_contents("/path/to/binary/file"); $esc = pg_escape_bytea($data); $unesc = pg_unescape_bytea($esc); print($unesc == $data ? "equal" : "different"); ?> Expected result: ---------------- "equal" Actual result: -------------- "different" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45964&edit=1