Name
mysql_fetch_lengths
Synopsis
array mysql_fetch_lengths(qresource query
)
Returns
an array of attribute lengths associated with the most recently
retrieved row of data. The argument to the function is a
query
result handle that has been used to
retrieve at least one row. The elements of the returned array
correspond to the length of the values in the array returned from the
most recent call to mysql_fetch_row( )
,
mysql_fetch_array( )
, mysql_fetch_object(
)
, or mysql_fetch_assoc( )
.
This function returns the length of a value within the specific
result set, not the maximum length of an attribute as defined in the
database table. Use the function mysql_field_len(
)
to retrieve the maximum length of an attribute as defined
in the database table.
The function returns false
on error.
Example
<?php $query = "SELECT * FROM presents"; $connection = mysql_connect("localhost", "fred", "shhh"); mysql_select_db("wedding", $connection); $result = mysql_query($query, $connection); while ($row = mysql_fetch_row($result)) { echo "The total length of this row is: "; $row2 = mysql_fetch_lengths($result); $length = 0; foreach ($row2 as $element) $length += $element; echo $length . "\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.