php8.5
Home/ Manual/ mysql / functions/ mysql_num_fields

mysql_num_fields

PHP function Edit on GitHub ✎

(PHP 4, PHP 5)

Get number of fields in result

Note mysqli_num_fieldsPDOStatement::columnCount

Description

mysql_num_fields(resource $result): int|false

Retrieves the number of fields from a query.

Parameters

Return Values

Returns the number of fields in the result set resource on successFalseforfailure.

Examples

A mysql_num_fields() example

php
<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}

/* returns 2 because id,email === two fields */
echo mysql_num_fields($result);
?>

Notes

See Also

Source: reference/mysql/functions/mysql-num-fields.xml · from the official PHP manual (php/doc-en)