Name

mysql_field_len

Synopsis

int mysql_field(qresource query, int attribute)

Returns the defined maximum length of an attribute in a result set. The first parameter is a query resource handle returned from a prior call to mysql_list_fields( ), mysql_query( ), or mysql_unbuffered_query( ). The second argument is the ordinal number of the attribute in the SQL query. The first attribute is numbered zero.

This function returns the maximum length of the attribute as defined in the database table, not the length of a value within a specific result set. Use the function mysql_fetch_lengths( ) to retrieve the length of specific values.

Example

<?php
  $connection = mysql_connect("localhost", "fred", "shhh");
  
  $result = mysql_list_fields("wedding", "presents");
  
  for($x=0; $x < mysql_num_fields($result); $x++)
     echo mysql_field_name($result, $x) . 
          " has a maximum length of " . 
          mysql_field_len($result, $x) . "\n";
?>

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.