mysqli_stmt_fetch,とは? わかりやすく解説

Weblio 辞書 > コンピュータ > PHP関数リファレンス > mysqli_stmt_fetch,の意味・解説 

mysqli_stmt_fetch,

(PHP 5)
mysqli_stmt_fetch, stmt->fetch() — プリペアドステートメントから結果を取得し、バインド変数に格納する

説明

手続き型:
bool mysqli_stmt_fetch ( mysqli_stmt stmt )
オブジェクト指向型(メソッド):
class mysqli_stmt {
bool fetch ( void )
} プリペアドステートメントから結果を読み込み、 mysqli_stmt_bind_result() でバインドした変数に格納します。
注意: mysqli_stmt_fetch() をコールする前に、すべての カラムがバインド済みである必要があることに注意しましょう。

パラメータ

stmt
手続き型のみ: mysqli_stmt_init() が返すステートメント ID。

返り値

表 183. 返り値
説明
TRUE成功。データが取得されました。
FALSEエラーが発生しました。
NULL行/データがもうありません。あるいは、データの切り詰めが発生しました。

例 1465. オブジェクト指向型
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 150,5";

if ($stmt = $mysqli->prepare($query)) {

   /* ステートメントを実行します */
   $stmt->execute();

   /* 結果変数をバインドします */
   $stmt->bind_result($name, $code);

   /* 値を取得します */
   while ($stmt->fetch()) {
       printf ("%s (%s)\n", $name, $code);
   }

   /* ステートメントを閉じます */
   $stmt->close();
}

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

例 1466. 手続き型
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 150,5";

if ($stmt = mysqli_prepare($link, $query)) {

   /* ステートメントを実行します */
   mysqli_stmt_execute($stmt);

   /* 結果変数をバインドします */
   mysqli_stmt_bind_result($stmt, $name, $code);

   /* 値を取得します */
   while (mysqli_stmt_fetch($stmt)) {
       printf ("%s (%s)\n", $name, $code);
   }

   /* ステートメントを閉じます */
   mysqli_stmt_close($stmt);
}

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

上の例の出力は以下となります。

Rockford (USA)
Tallahassee (USA)
Salinas (USA)
Santa Clarita (USA)
Springfield (USA)

  

参考

mysqli_prepare()
mysqli_stmt_errno()
mysqli_stmt_error()
mysqli_stmt_bind_result()




英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「mysqli_stmt_fetch,」の関連用語

mysqli_stmt_fetch,のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



mysqli_stmt_fetch,のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
PHP Documentation GroupPHP Documentation Group
Copyright © 1997 - 2025 by the PHP Documentation Group.

©2025 GRAS Group, Inc.RSS