Replacing mysql_field_flags() for column attributes

mysql_field_flags() returned a space-separated set of flags for a field in PHP's removed MySQL extension. Current code should inspect table metadata directly or use MySQLi result-field metadata.

Historical mysql_field_flags()

<?php
// Historical only.
$result = mysql_query('SELECT * FROM student');
$flags = mysql_field_flags($result, 0);
echo $flags;
?>

SHOW FULL COLUMNS

SHOW FULL COLUMNS FROM student;

The result exposes useful schema attributes such as Null, Key, Default, Extra, collation and privileges. For many tutorials this is more readable than decoding numeric flag bits.

MySQLi field metadata

<?php
$result = $connection->query(
    'SELECT id, name, class, mark FROM student'
);
$field = $result->fetch_field_direct(0);
echo 'Name: ' . htmlspecialchars($field->name) . '<br>';
echo 'Flags bitmask: ' . $field->flags;
?>

INFORMATION_SCHEMA for explicit attributes

SELECT
    COLUMN_NAME,
    IS_NULLABLE,
    COLUMN_KEY,
    COLUMN_DEFAULT,
    EXTRA,
    DATA_TYPE,
    COLUMN_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'sql_tutorial'
  AND TABLE_NAME = 'student'
ORDER BY ORDINAL_POSITION;

Older versions of this page also used TYPE=MyISAM, integer display widths and each(). Those patterns are not needed for column-attribute inspection and are not carried forward as current examples.

Column metadata · Field/schema length · Field names · Field types · SHOW TABLES

← All PHP & MySQL topics




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer