結果セット内のフィールド(列)を表すオブジェクトの配列を返し、各フィールドの名前、テーブル、および最大長を出力します:
<?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 all fields
$fieldinfo=mysqli_fetch_fields($result);
foreach ($fieldinfo as $val)
{
printf("Name: %s\n",$val->name);
printf("Table: %s\n",$val->table);
printf("max. Len: %d\n",$val->max_length);
}
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
mysqli_fetch_fields() 関数は、結果セット内のフィールド(列)を表すオブジェクトの配列を返します。
mysqli_fetch_fields(result);
パラメータ | 説明 |
---|---|
result | 必須。mysqli_query()、mysqli_store_result()またはmysqli_use_result()が返す結果セットの識別子を指定する |
返り値: | フィールド定義情報を含むオブジェクトの配列を返す。情報がない場合はFALSEを返します。オブジェクトには、次のプロパティがある:
|
---|---|
PHP バージョン: | 5+ |