Page 1 of 1

Need to unpack varbinary(10) with PHP.

Posted: Mon Mar 07, 2011 11:41 am
by Aristona
Hello,

I have a column in my database which contains varbinary data.
So, I wrote a code like this.

Code: Select all

print_r(unpack('varbinary(MAX)', $row['Blah']));
However, it outputs "Array ( [arbinary(MAX)] => 0 )".

Unpack doesn't support varbinary or am I doing something wrong?

Thanks.

Re: Need to unpack varbinary(10) with PHP.

Posted: Tue Mar 08, 2011 5:33 am
by Darhazer
what is the data in the field (you can put text in varbinary for example)
and what output you expect?
how the data was put in the database?
and read the format of the string that you send to unpack, every character has it's own meaning
For example this will give you hex representation of the data:

Code: Select all

unpack('H*', $row['Blah']);
(but hex representation can be retrieved using the build-in bin2hex())