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!
See comment at http://www.php.net/manual/en/mysqli-result.fetch-fields.php#101828
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 formStarting from right, you can now read that the field has following flags
Other way to check, for specific flag is using binary conjunction operator
&
and mysqli constants as provided by nickb in comment below: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: