SELECT users from MySQL database by privileges bitmask?

前端 未结 2 514
花落未央
花落未央 2020-12-30 00:27

I have users table and want to SELECT some rows by bitmask criteria. I\'ll try to explain my problem with small example.

Structure of table users

相关标签:
2条回答
  • 2020-12-30 00:48

    [...] want to SELECT some fields

    Wrong. You want to select some Rows. Columns are usually called fields.

    You are supposed to read the Documentation: Bit Functions are documented for mysql.

    So you can try:

    Select * from users WHERE (user_privileges & 1) >0

    0 讨论(0)
  • 2020-12-30 01:07
    SELECT
        *
    FROM
        users
    WHERE
        (user_privileges & <level>) = <level>
    

    <level> being the access level you want to search on (e.g. 1, 5, 9, 130, etc.)

    0 讨论(0)
提交回复
热议问题