Page 1 of 1

Processing BIT data "\x0\x0\x0\x0\x0\x0\x0\x5"

Posted: Mon Oct 19, 2009 5:42 am
by gmckay
I have setup a BIT(64) field in MYSQL.
I can populate this field OK converting the flags "0000000000000000000000000000000000000000000000000000000000000101", but when the data is returned in a query it is represented as "\x0\x0\x0\x0\x0\x0\x0\x5" and I can't find any hints online how to convert this back to flags....

I've pulled out what little hair I had left, threw my arms in the air and post this plea for HELP!!

I know you are going to say 'why?', but I'm not looking for criticism, just an answer...

p.s. I'm a mainframe COBOL programmer and all this php stuff is a bit foreign...

Re: Processing BIT data "\x0\x0\x0\x0\x0\x0\x0\x5"

Posted: Mon Oct 19, 2009 10:09 am
by Weirdan
[sql] SELECT bin(fieldName) FROM tableName ... [/sql]

Re: Processing BIT data "\x0\x0\x0\x0\x0\x0\x0\x5"

Posted: Mon Oct 19, 2009 3:52 pm
by gmckay
Thanks, I'll have a go at that, but as that will require me to change all the SELECT statements from "SELECT *" to "SELECT bin(fieldName), fieldName2, ...." I was really looking for a post-select coding solution.

Re: Processing BIT data "\x0\x0\x0\x0\x0\x0\x0\x5"

Posted: Mon Oct 19, 2009 4:46 pm
by gmckay
Coding "SELECT *, bin(fieldName) as flags .." worked well. I'll just propagate that wherever needed.
Thanks muchly...

Re: Processing BIT data "\x0\x0\x0\x0\x0\x0\x0\x5"

Posted: Tue Oct 20, 2009 9:45 am
by Weirdan
gmckay wrote:I was really looking for a post-select coding solution.
That would really complicate things, especially if you use 32bit php (because you're using 64bit bit field). Anyway, just in case you'd ever need it: you would need to unpack data to two unsigned longs (note that byte order is machine-dependent) and then either convert them to bit string using decbin or use them as ints and perform bit arithmetics on them yourself.