I have a string like \314\002\012\001 which I need to convert into a base64 encoded byte string.
\314\002\012\001
You should be able to use the built-in php function pg_unescape_bytea. There is an example on that page.