1

私が理解している限り、準備済みステートメントを使用する利点は、SQL インジェクションを防ぐことです。

SELECT と INSERT を使用して、準備されたステートメントでクエリを作成することができました。

しかし、 に相当するものを達成するにはselect count()、頭を壁にぶつけています。
PHPマニュアルには次のように記載されています。

if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")) {

    /* determine number of rows result set */
    $row_cnt = mysqli_num_rows($result);

    printf("Result set has %d rows.\n", $row_cnt);

    /* close result set */
    mysqli_free_result($result);
}

私も準備済みのステートメントでこれをやろうとしています。しかし、多分私はすべきではありませんか?

これは私がしようとしているものです:

$boy = 'yes';
$age   = 1;

$result = mysqli_prepare ($bdd, 'SELECT boy , age FROM photo WHERE  boy = ? AND age= ?' );

mysqli_stmt_bind_param( $result, "si", $boy , $age );
mysqli_stmt_execute( $result );

$row_cnt = mysqli_num_rows( $result );
printf( "Le jeu de résultats a %d lignes.\n", $row_cnt );

しかし、私が何をしようとしても、常に同じタイプのエラーが発生します

警告: mysqli_num_rows() は、パラメーター 1 が mysqli_result であると想定します。オブジェクトは C:\wamp\www\page.com\pic.php の 36 行目に指定されています

4

1 に答える 1

1

mysqli_stmt_num_rows私はあなたがと組み合わせて探していると思います-http mysqli_stmt_store_result: //www.php.net/manual/en/mysqli-result.num-rows.php

<?php
$boy = 'yes';
$age   = 1;

$result = mysqli_prepare ($bdd, 'SELECT boy , age FROM photo WHERE  boy = ? AND age= ?' );

mysqli_stmt_bind_param( $result, "si", $boy , $age );
mysqli_stmt_execute( $result );

// You may need this too...
mysqli_stmt_store_result( $result );

$row_cnt = mysqli_stmt_num_rows( $result );
printf( "Le jeu de résultats a %d lignes.\n", $row_cnt );
?>
于 2013-02-21T00:19:15.250 に答える