【发布时间】:2015-01-31 10:43:51
【问题描述】:
我在 MySQL 表中有以下数据
“数据转储” 2 电话呼叫 001 2 电话呼叫 010 2 电话呼叫 100 2 个电话呼叫 1000 2 phone_calls 10000 2 phone_calls 100000
如果我运行 PHP 代码来执行按位或这样的操作
echo bindec('001') | bindec('010') | bindec('100') | bindec('1000') | bindec('10000') | bindec('100000');
我得到 63 的输出“这是预期的”
如果我手动执行或操作
000001
000010
000100
001000
010000
100000
======
111111
the result = 111111 which is `32 + 16 + 8 + 4 + 2 + 1 = 63`
当我在 MySQL 中运行以下查询时
SELECT user_id, section_name, BIT_OR(permission_type) AS final
FROM permissions
WHERE section_name ='phone_calls' and user_id = 2
GROUP BY user_id, section_name
基本上是在上面列出的“数据转储”上运行BIT_OR(),输出是
2 phone_calls 108543
为什么 MySQL 给我 108543 而 PHP 给我 63?如何让 MySQL 给我 63?
【问题讨论】:
标签: php mysql bit-manipulation aggregate-functions bitwise-operators