Get the length of the fields in the result set in PHP
Description
The following code shows how to get the length of the fields in the result set.
Example
/* ww w . jav a2 s .c om*/
<?php
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT * FROM employee";
if ($result=mysqli_query($con,$sql)){
$row=mysqli_fetch_row($result);
// Display field lengths
foreach (mysqli_fetch_lengths($result) as $i=>$val){
printf("Field %2d has length: %2d\n",$i+1,$val);
}
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
The code above generates the following result.