Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8218893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:57:34+00:00 2026-06-07T12:57:34+00:00

Using mysqli, I can get information about fields like so $field = mysqli_fetch_field_direct($result, $fieldCount);

  • 0

Using mysqli, I can get information about fields like so

$field = mysqli_fetch_field_direct($result, $fieldCount);

and I can get the field flags from the result using

$field->flags

The PHP manual says that this returns “An integer representing the bit-flags for the field.” but that’s all the info I can find. How can I interpret the bit flags? So far, I’ve worked out that

Integers (length of field doesn’t matter) return the following bit flags depending on the attributes specified:

primary key 49967
primary & unique 53255
unique key 53251
foreign key 53257
unique & index 53259 (Auto increment 49675)

Thanks for any help you can offer!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:57:36+00:00Added an answer on June 7, 2026 at 12:57 pm

    See comment at http://www.php.net/manual/en/mysqli-result.fetch-fields.php#101828

    NOT_NULL_FLAG = 1                                                                             
    PRI_KEY_FLAG = 2
    UNIQUE_KEY_FLAG = 4                         
    MULTIPLE_KEY_FLAG = 8
    BLOB_FLAG = 16
    UNSIGNED_FLAG = 32
    ZEROFILL_FLAG = 64                    
    BINARY_FLAG = 128                                       
    ENUM_FLAG = 256
    AUTO_INCREMENT_FLAG = 512
    TIMESTAMP_FLAG = 1024
    SET_FLAG = 2048
    PART_KEY_FLAG = 16384
    GROUP_FLAG = 32768
    NUM_FLAG = 32768
    UNIQUE_FLAG = 65536
    

    Notice that every number posted above is a power of 2. (1 = 2^0, 2 = 2^1, 4 = 2^2 and so on). In other words, each of them corresponds to one bit in a number. To read what 49967 means, you can for example display it in binary form

    >> decbin(49967);
    '1100001100101111'
    

    Starting from right, you can now read that the field has following flags

    NOT_NULL 
    PRI_KEY  
    UNIQUE_KEY
    MULTIPLE_KEY
    UNSIGNED
    ENUM
    AUTO_INCREMENT
    GROUP
    UNIQUE
    

    Other way to check, for specific flag is using binary conjunction operator & and mysqli constants as provided by nickb in comment below:

    >> echo MYSQLI_NOT_NULL_FLAG & 49967
    1
    >> echo MYSQLI_PRI_KEY_FLAG & 49967
    2
    >> echo MYSQLI_UNIQUE_KEY_FLAG & 49967
    4
    >> echo MYSQLI_MULTIPLE_KEY_FLAG & 49967
    8
    >> echo MYSQLI_BLOB_FLAG & 49967
    0
    

    Basically you gat non-zero value for flags that are set, and 0 for flags that are unset. You can safely use it in conditions like this:

    if($fieldFlags & MYSQLI_PRI_KEY_FLAG) {
      echo 'this field is a primary key';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does anyone know if you can get individual field comments from mysql using Zend
How can i get the current view criteria using php and the mysql statement
I'm looking at ways to get information from my MySQL DB using iOS. The
I am pulling some data from mysql database using PHP, now I would like
I'm trying to get mysql gem installed for use on rails, using jruby, can't
Using PHP, I can convert MySQL data or static table data to csv, Excel,
I was wondering how can I validate a single checkbox using PHP and MySQL.
I'm trying to create a query that pulls information about sellers from my database,
Can I create tables using Stored Procedures? I am using MySQL. I had searched
i can't display the image on my aspx view.. i'm using mysql as database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.