PHP mysqli_fetch_lengths() 関数

❮ PHP MySQLi リファレンス

結果セットのフィールドの長さを返します:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="SELECT * FROM Persons ORDER BY Lastname";

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);
?>

定義と用法

mysqli_fetch_lengths() 関数は、結果セットのフィールドの長さを返します。


構文

mysqli_fetch_lengths(result);

パラメータ 説明
result 必須。mysqli_query()、mysqli_store_result()またはmysqli_use_result()が返す結果セットの識別子を指定する

技術内容
返り値: 各フィールド(列)を表す整数の配列を返します。エラー時には FALSE を返します
PHP バージョン: 5+

❮ PHP MySQLi リファレンス