PHP mysql_field_len() Function

Definition and Usage

The mysql_field_len() function returns the length of the specified field.

If successful, returns the length of the field, if failed, returns false.

Syntax

mysql_field_len(data,field_offset)
Parameters Description
data Required. The data pointer to use. The data pointer is from mysql_query() The result returned.
field_offset Required. Indicates which field to start returning from. 0 indicates the first field.

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);
$length = mysql_field_len($result, 0);
echo $length;
mysql_close($con);
?>

Output:

20