PHP 8.3.4 Released!

mysqli::$field_count

mysqli_field_count

(PHP 5, PHP 7, PHP 8)

mysqli::$field_count -- mysqli_field_count直近のクエリのカラムの数を返す

説明

オブジェクト指向型

手続き型

mysqli_field_count(mysqli $mysql): int

mysql が指す接続における直近のクエリの カラムの数を返します。この関数は、クエリが空でない結果セットを 生成すべきなのかそうではないのかを判断するために mysqli_store_result() 関数を使用する際に有用です。

パラメータ

link

手続き型のみ: mysqli_connect() あるいは mysqli_init() が返す mysqliオブジェクト。

戻り値

結果セットのフィールド数を整数で返します。

例1 $mysqli->field_count の例

オブジェクト指向型

<?php
$mysqli
= new mysqli("localhost", "my_user", "my_password", "test");

$mysqli->query( "DROP TABLE IF EXISTS friends");
$mysqli->query( "CREATE TABLE friends (id int, name varchar(20))");

$mysqli->query( "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')");


$mysqli->real_query("SELECT * FROM friends");

if (
$mysqli->field_count) {
/* これは select/show あるいは describe クエリです */
$result = $mysqli->store_result();

/* 結果セットを処理します */
$row = $result->fetch_row();

/* 結果セットを開放します */
$result->close();
}

/* 接続を閉じます */
$mysqli->close();
?>

手続き型

<?php
$link
= mysqli_connect("localhost", "my_user", "my_password", "test");

mysqli_query($link, "DROP TABLE IF EXISTS friends");
mysqli_query($link, "CREATE TABLE friends (id int, name varchar(20))");

mysqli_query($link, "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')");

mysqli_real_query($link, "SELECT * FROM friends");

if (
mysqli_field_count($link)) {
/* これは select/show あるいは describe クエリです */
$result = mysqli_store_result($link);

/* 結果セットを処理します */
$row = mysqli_fetch_row($result);

/* 結果セットを開放します */
mysqli_free_result($result);
}

/* 接続を閉じます */
mysqli_close($link);
?>
add a note

User Contributed Notes 1 note

up
-30
dedlfix
17 years ago
There are MYSQLI_TYPE_* constants for the type property (listed in http://php.net/manual/en/ref.mysqli.php).

e.g.
<?php
if ($finfo->type == MYSQLI_TYPE_VAR_STRING)
// a VARCHAR
To Top