Warning: file_put_contents(): Only -1 of 59 bytes written, possibly out of free disk space in /var/www/html/index.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/index.php:3) in /var/www/html/cache.php on line 23

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/index.php:3) in /var/www/html/cache.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/index.php:3) in /var/www/html/cache.php on line 25
mysqli_stmt_execute mysqli_stmt_field_count mysqli PHP Manual mysqli_stmt_fetch stmt->fetch() (No version information available, might be only in CVS) stmt->fetch() — プリペアドステー...
Forum und email

mysqli_stmt_fetch

stmt->fetch()

(No version information available, might be only in CVS)

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

説明

手続き型:

bool mysqli_stmt_fetch ( mysqli_stmt $stmt )

オブジェクト指向型(メソッド):

mysqli_stmt
bool fetch ( void )

プリペアドステートメントから結果を読み込み、 mysqli_stmt_bind_result() でバインドした変数に格納します。

注意: mysqli_stmt_fetch() をコールする前に、すべての カラムがバインド済みである必要があることに注意しましょう。

パラメータ

stmt

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

返り値

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

Example#1 オブジェクト指向型

<?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();
?>

Example#2 手続き型

<?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)