PHP mysqli_num_fields() 関数

❮ 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 Lastname,Age FROM Persons ORDER BY Lastname";

if ($result=mysqli_query($con,$sql))
  {
  // Return the number of fields in result set
  $fieldcount=mysqli_num_fields($result);
  printf("Result set has %d fields.\n",$fieldcount);
  // Free result set
  mysqli_free_result($result);
  }

mysqli_close($con);
?>

定義と用法

mysqli_num_fields() 関数は、結果セット内のフィールド(列)数を返します。


構文

mysqli_num_fields(result);

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

技術内容
返り値: 結果セット内のフィールド数を返しますt
PHP バージョン: 5+

❮ PHP MySQLi リファレンス