0

I have a SQL statement where a make a conversion with "convert_from(X, 'UTF8')" on a 'bytea'-field in PostgreSQL. I want to make the conversion not in SQL but in PHP. Is there an equivalent function for doing this in PHP?

2 Answers 2

1
iconv('UTF-8', $targetCharset, $x)

or

mb_convert_encoding($x, $targetCharset, 'UTF-8')

http://php.net/manual/en/function.iconv.php
http://php.net/mb_convert_encoding

You will have to specify the target character set, which is implied by the database encoding in the Postgres function.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, what is your end goal? What do you want to convert to?
0

the problem was that postgresql returns the field hex-coded. My solution in PHP now looks like this:

$str = pack('H*', str_replace('\x', '', $obj->BinData));

With this it is possible to retrieve text of a bytea-field.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.