mysql_field_type() returned a simplified field type from PHP's removed MySQL extension. For modern applications, use MySQL schema metadata when you need the table's declared type.
<?php
// Historical only.
$result = mysql_query('SELECT * FROM student');
$type = mysql_field_type($result, 0);
echo $type;
?>
SELECT
COLUMN_NAME,
DATA_TYPE,
COLUMN_TYPE,
IS_NULLABLE,
COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'sql_tutorial'
AND TABLE_NAME = 'student'
ORDER BY ORDINAL_POSITION;
DATA_TYPE gives the base type, while COLUMN_TYPE retains additional type details.
<?php
$stmt = $dbo->query('SELECT COUNT(*) AS total FROM student');
$meta = $stmt->getColumnMeta(0);
print_r($meta);
?>
getColumnMeta() can be useful for result-set metadata, but schema queries are clearer when you specifically need the declared MySQL type.
<?php
$result = $connection->query(
'SELECT id, name, class, mark FROM student'
);
$field = $result->fetch_field_direct(0);
echo 'MySQL type code: ' . $field->type;
?>
For choosing the right schema type, continue with the MySQL data types hub and its numeric, date/time, and BLOB pages.
Data types · Column metadata · Field/schema length · Field names · Number of fields
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.