Need to unpack varbinary(10) with PHP.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

Need to unpack varbinary(10) with PHP.

Post 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.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

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

Post 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())
Post Reply