Easy Tutorial
❮ Func Xml Get Current Line Number Func Filesystem Dirname ❯

PHP mysqli_fetch_lengths() Function

PHP MySQLi Reference Manual

Returns the lengths of the fields in the result set:

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

$sql = "SELECT name, url FROM websites ORDER BY alexa";

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 length: %2d", $i + 1, $val);
        echo "<br>";
    }

    // Free the result set
    mysqli_free_result($result);
}

mysqli_close($con);
?>

Definition and Usage

The mysqli_fetch_lengths() function returns the lengths of the fields in the result set.


Syntax

Parameter Description
result Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result().

Technical Details

Return Value: Returns an array with the lengths of each field (column) if successful, or FALSE on failure.
PHP Version: 5+
--- ---
❮ Func Xml Get Current Line Number Func Filesystem Dirname ❯