結果セット内の単一のフィールド(列)のメタデータを返し、次にフィールドの名前、テーブル、および最大長を出力します:
<?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 Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql))
{
// Get field information for "Age"
$fieldinfo=mysqli_fetch_field_direct($result,1);
printf("Name: %s\n",$fieldinfo->name);
printf("Table: %s\n",$fieldinfo->table);
printf("max. Len: %d\n",$fieldinfo->max_length);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
mysqli_fetch_field_direct() 関数は、結果セット内の単一のフィールド(列)のメタデータをオブジェクトとして返します。
mysqli_fetch_field_direct(result,fieldnr);
パラメータ | 説明 |
---|---|
result | 必須。mysqli_query()、mysqli_store_result()またはmysqli_use_result()が返す結果セットの識別子を指定する |
fieldnr | 必須。フィールド番号を指定する。 この値は 0 から フィールド数 - 1 までの範囲でなければならない |
返り値: | フィールド定義情報を含むオブジェクトを返します。情報がない場合はFALSEを返します。オブジェクトには、次のプロパティがあります:
|
---|---|
PHP バージョン: | 5+ |