Name

mysql_field_flags

Synopsis

string mysql_field_flags(qresource query, int attribute)

Returns a string containing any special flags associated with an attribute in a query result set. The first argument is a query resource handle returned from a prior call to mysql_list_fields( ), mysql_query( ), or mysql_unbuffered_query( ). The second argument is the ordinal number of the attribute in the SQL query. The first attribute is numbered zero.

The flags are returned as a string and are delimited with a space character. The following flags are reported:

not_null

The attribute cannot contain a NULL value.

primary_key

The attribute is a primary key.

unique_key

The attribute is a unique key.

multiple_key

The attribute is a non-unique key.

blob

The attribute is a BLOB type.

unsigned

The attribute is an unsigned integer.

zerofill

The attribute is a zero-filled numeric.

binary

The attribute may contain binary data and will use binary-safe comparisons.

enum

The attribute is an enumeration, which can contain one of several predefined values.

auto_increment

The attribute has the auto_increment modifier.

timestamp

The attribute is an automatic timestamp field.

Example

<?php
  $connection = mysql_connect("localhost", "fred", "shhh");
  
  $result = mysql_list_fields("wedding", "presents");
  
  for($x=0; $x < mysql_num_fields($result); $x++)
     echo mysql_field_name($result, $x) . 
          " has the properties: " . 
          mysql_field_flags($result, $x) . "\n";
?>

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.