|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-10-26 13:06 UTC] kk219459 at students dot mimuw dot edu dot pl
[2009-03-13 13:35 UTC] jani@php.net
[2009-03-21 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
Description: ------------ OpenBSD 4.1 Apache/1.3.29 php5-core-5.1.6p1 postgresql-client-8.2.4 I want to insert some binary data to a table. $q = "UPDATE tbl SET data = decode($1, 'base64') WHERE id = $2"; $params = array(base64_encode('binary string'), 123); $res = pg_query_params($q, $params); OK $q = "UPDATE tbl SET data = $1::bytea WHERE id = $2"; $params = array('binary string', 123); $res = pg_query_params($q, $params); ERROR: invalid byte sequence for encoding "UTF8": 0x89 HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". This could possibly work, but does not. Ok, not a problem. (end of introduction) Reproduce code: --------------- # first $q = "UPDATE tbl SET data = decode($1, 'escape') WHERE id = $2"; $params = array(pg_escape_bytea('binary string'), 123); $res = pg_query_params($q, $params); # second $q = "UPDATE tbl SET data = $1::bytea WHERE id = $2"; $params = array(pg_escape_bytea('binary string'), 123); $res = pg_query_params($q, $params); Expected result: ---------------- Be sure to replace 'binary string' with something more challenging! At least one of these should work (insert the data correctly) Actual result: -------------- Both approaches give the same result. The data gets loaded, but incorrectly. select length(data) from tbl; -- too large data contains character sequences like '\000' instead of their values. btw. select content = decode(encode(data, 'escape'), 'escape') from tbl; -- works (sequence of TRUEs)