PHP mysql_num_fields() function

Definition and usage

The mysql_num_fields() function returns the number of fields in the result set.

If it fails, it returns false.

Syntax

mysql_num_fields(data)
Parameter Description
data Required. Specifies the data pointer to be used. This data pointer is generated by the mysql_query() function.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * FROM person";
$result = mysql_query($sql,$con);
echo mysql_num_fields($result);
mysql_close($con);
?>

Output like:

3