PHP mysqli_fetch_lengths() Function
In this chapter you will learn:
- Definition for PHP mysqli_fetch_lengths() Function
- Syntax for PHP mysqli_fetch_lengths() Function
- Parameter for PHP mysqli_fetch_lengths() Function
- Return for PHP mysqli_fetch_lengths() Function
- Example - returns the length of the columns in the result set
Definition
The mysqli_fetch_lengths() function returns the length of the fields in the result set.
Syntax
PHP mysqli_fetch_lengths() Function has the following syntax.
mysqli_fetch_lengths(result);
Parameter
Parameter | Is Required | Description |
---|---|---|
result | Required. | Result set returned by mysqli_query(), mysqli_store_result() or mysqli_use_result() |
Return
It returns an array if integer that represents the size of each column or FALSE if an error occurs.
Example
The following code returns the length of the columns in the result set.
<?php/*from j a v a 2 s .c om*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT * FROM emp ";
if ($result=mysqli_query($con,$sql)){
$row=mysqli_fetch_row($result);
foreach (mysqli_fetch_lengths($result) as $i=>$val){
printf("Field %2d has length: %2d\n",$i+1,$val);
}
mysqli_free_result($result);
}
mysqli_close($con);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_fetch_object() Function
- Syntax for PHP mysqli_fetch_object() Function
- Parameter for PHP mysqli_fetch_object() Function
- Return for PHP mysqli_fetch_object() Function
- Example - returns the current row of a result set, then print each field's value
Home » PHP Tutorial » PHP MySQLi Functions