結果セットの次のフィールド(列)を返し、各フィールドの名前、テーブル、および最大長を出力します:
<?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
while ($fieldinfo=mysqli_fetch_field($result))
{
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() 関数は、結果セットの次のフィールド(列)をオブジェクトとして返します。
mysqli_fetch_field(result);
パラメータ | 説明 |
---|---|
result | 必須。mysqli_query()、mysqli_store_result()またはmysqli_use_result()が返す結果セットの識別子を指定する |
返り値: | フィールド定義情報を含むオブジェクトを返します。情報がない場合はFALSEを返します。オブジェクトには、次のプロパティがあります:
|
---|---|
PHP バージョン: | 5+ |